dexter.c revision cc910c475085f94bd30fc1b6e16363872424f780
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova/* ====================================================================
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Redistribution and use in source and binary forms, with or without
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu * modification, are permitted provided that the following conditions
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 1. Redistributions of source code must retain the above copyright
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * notice, this list of conditions and the following disclaimer.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * 2. Redistributions in binary form must reproduce the above copyright
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * notice, this list of conditions and the following disclaimer in
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * the documentation and/or other materials provided with the
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * distribution.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 3. All advertising materials mentioning features or use of this
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * software must display the following acknowledgment:
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * "This product includes software developed by the Apache Group
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * for use in the Apache HTTP server project (http://www.apache.org/)."
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 4. The names "Apache Server" and "Apache Group" must not be used to
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * endorse or promote products derived from this software without
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * prior written permission. For written permission, please contact
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * apache@apache.org.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 5. Products derived from this software may not be called "Apache"
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * nor may "Apache" appear in their names without prior written
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * permission of the Apache Group.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 6. Redistributions of any form whatsoever must retain the following
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * acknowledgment:
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * "This product includes software developed by the Apache Group
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * for use in the Apache HTTP server project (http://www.apache.org/)."
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * OF THE POSSIBILITY OF SUCH DAMAGE.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * ====================================================================
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * This software consists of voluntary contributions made by many
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * individuals on behalf of the Apache Group and was originally based
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * on public domain software written at the National Center for
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * Supercomputing Applications, University of Illinois, Urbana-Champaign.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * For more information on the Apache Group and the Apache HTTP server
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * project, please see <http://www.apache.org/>.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#include "http_config.h" /* for read_config */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#include "http_core.h" /* for get_remote_host */
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Actual definitions of config globals
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovastatic int threads_to_start = 0; /* Worker threads per child */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next != NULL) {stmt;}} while (0)
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova#define SAFE_ACCEPT(stmt) do {stmt;} while (0)
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * The max child slot ever assigned, preserved across restarts. Necessary
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * to deal with NumServers changes across SIGWINCH restarts. We use this
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * value to optimize routines that have to scan the entire scoreboard.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovastatic char ap_coredump_dir[MAX_STRING_LEN];
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovastatic pthread_mutex_t pipe_of_death_mutex;
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova/* *Non*-shared http_main globals... */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova/* one_process --- debugging mode variable; can be set from the command line
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * with the -X flag. If set, this gets you the child_main loop running
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * in the process which originally started up (no detach, no make_child),
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * which is a pretty nice debugging environment. (You'll get a SIGHUP
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * early in standalone_main; just continue through. This is the server
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * trying to kill off any child processes which it might have lying
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * around --- Apache doesn't keep track of their pids, it just sends
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * SIGHUP to the process group, ignoring it in the root process.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * Continue through and you'll be fine.).
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova/* used to maintain list of children which aren't part of the scoreboard */
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovatypedef struct other_child_rec other_child_rec;
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova void (*maintenance) (int, void *, ap_wait_t);
static int worker_thread_count;
static int idle_thread_count;
return (server_conf);
if (pchild) {
#ifdef HAS_OTHER_CHILD
static void probe_writable_fds(void)
int fd_max;
int rc;
fd_max = 0;
if (fd_max == 0)
if (rc == 0)
int i, status;
int not_dead_yet;
#ifdef HAS_OTHER_CHILD
not_dead_yet = 0;
for (i = 0; i < max_daemons_limit; ++i) {
++not_dead_yet;
switch (tries) {
pid);
pid);
#ifdef HAS_OTHER_CHILD
else if (waitret == 0) {
++not_dead_yet;
if (!not_dead_yet) {
#ifndef INTERVAL_OF_WRITABLE_PROBES
static int wait_or_timeout_counter;
int ret;
#ifdef HAS_OTHER_CHILD
if (ret > 0) {
return ret;
#if defined(NSIG)
static void siglist_init(void)
int sig;
#ifdef SIGHUP
#ifdef SIGINT
#ifdef SIGQUIT
#ifdef SIGILL
#ifdef SIGTRAP
#ifdef SIGIOT
#ifdef SIGABRT
#ifdef SIGEMT
#ifdef SIGFPE
#ifdef SIGKILL
#ifdef SIGBUS
#ifdef SIGSEGV
#ifdef SIGSYS
#ifdef SIGPIPE
#ifdef SIGALRM
#ifdef SIGTERM
#ifdef SIGUSR1
#ifdef SIGUSR2
#ifdef SIGCLD
#ifdef SIGCHLD
#ifdef SIGPWR
#ifdef SIGWINCH
#ifdef SIGURG
#ifdef SIGPOLL
#ifdef SIGIO
#ifdef SIGSTOP
#ifdef SIGTSTP
#ifdef SIGCONT
#ifdef SIGTTIN
#ifdef SIGTTOU
#ifdef SIGVTALRM
#ifdef SIGPROF
#ifdef SIGXCPU
#ifdef SIGXFSZ
clean_child_exit(0);
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
void ap_start_shutdown(void)
#ifndef WIN32
static void set_signals(void)
#ifndef NO_USE_SIGACTION
if (!one_process) {
#if defined(SA_ONESHOT)
#ifdef SIGBUS
#ifdef SIGABORT
#ifdef SIGABRT
#ifdef SIGILL
#ifdef SIGINT
#ifdef SIGXCPU
#ifdef SIGXFSZ
#ifdef SIGPIPE
if (!one_process) {
#ifdef SIGBUS
#ifdef SIGABORT
#ifdef SIGABRT
#ifdef SIGILL
#ifdef SIGXCPU
#ifdef SIGXFSZ
#ifdef SIGHUP
#ifdef SIGWINCH
#ifdef SIGPIPE
int num_listeners = 0;
return num_listeners;
int ap_graceful_stop_signalled(void)
return is_graceful;
static void *worker_thread(void *);
static int reported = 0;
if (!reported) {
int srv;
int ret;
char pipe_read_char;
while (!workers_may_exit) {
if (workers_may_exit) break;
if (!thread_just_started) {
thread_just_started = 0;
if (workers_may_exit) {
while (!workers_may_exit) {
if (srv < 0) {
if (workers_may_exit) break;
if (!workers_may_exit) {
goto got_fd;
curr_pollfd++;
goto got_fd;
if (!workers_may_exit) {
if (worker_thread_count == 0) {
return NULL;
static void child_main(void)
int signal_received;
if (unixd_setup_child()) {
worker_thread_count = 0;
for (i=0; i < threads_to_start; i++) {
switch (signal_received) {
case SIGTERM:
case SIGINT:
int pid;
if (one_process) {
set_signals();
child_main();
if (!pid) {
#ifdef AIX_BIND_PROCESSOR
child_main();
return number_to_start;
#ifndef MAX_SPAWN_RATE
static int hold_off_on_exponential_spawning;
static void perform_child_maintenance(void)
int free_length;
free_length = 0;
for (i = 0; i < num_daemons; ++i) {
++free_length;
last_non_dead = i;
if (free_length > 0) {
for (i = 0; i < free_length; ++i) {
int child_slot;
int pid;
if (pid >= 0) {
if (child_slot >= 0) {
#ifdef HAS_OTHER_CHILD
else if (is_graceful) {
else if (remaining_children_to_start) {
server_conf = s;
server_conf = s;
if (!is_graceful) {
set_signals();
if (!is_graceful) {
if (shutdown_pending) {
if (one_process) {
if (is_graceful) {
for (i = 0; i < num_daemons; ++i) {
for (i = 0; i < num_daemons; ++i) {
static void dexter_hooks(void)
one_process = 0;
static int restart_num = 0;
is_graceful = 0;
if (!one_process) {
unixd_detach();
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
if (min_spare_threads <= 0) {
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
const char *fname;
return err;
return NULL;
struct ap_thread_mutex {
return mtx;
{ NULL }
#include "xmlparse.h"