dexter.c revision d41217398f0e1031adbb6f5bd37f45737c805def
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Redistribution and use in source and binary forms, with or without
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * modification, are permitted provided that the following conditions
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * 1. Redistributions of source code must retain the above copyright
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * notice, this list of conditions and the following disclaimer.
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * 2. Redistributions in binary form must reproduce the above copyright
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * notice, this list of conditions and the following disclaimer in
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the documentation and/or other materials provided with the
b6055b7832a0e4d0818416252fff5925aaebae4brbb * distribution.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 3. The end-user documentation included with the redistribution,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * if any, must include the following acknowledgment:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * "This product includes software developed by the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Apache Software Foundation (http://www.apache.org/)."
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Alternately, this acknowledgment may appear in the software itself,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * if and wherever such third-party acknowledgments normally appear.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 4. The names "Apache" and "Apache Software Foundation" must
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * not be used to endorse or promote products derived from this
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * software without prior written permission. For written
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb * permission, please contact apache@apache.org.
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * 5. Products derived from this software may not be called "Apache",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * nor may "Apache" appear in their name, without prior written
ab172d76c59ec820ae07bbdd4d6f18a38955bfd6minfrin * permission of the Apache Software Foundation.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ab172d76c59ec820ae07bbdd4d6f18a38955bfd6minfrin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43c3e6a4b559b76b750c245ee95e2782c15b4296jim * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ab172d76c59ec820ae07bbdd4d6f18a38955bfd6minfrin * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e95f5a6ebefb83d0e8a82cbc4db7d354957a817dben * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
ab172d76c59ec820ae07bbdd4d6f18a38955bfd6minfrin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43c3e6a4b559b76b750c245ee95e2782c15b4296jim * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ab172d76c59ec820ae07bbdd4d6f18a38955bfd6minfrin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ab172d76c59ec820ae07bbdd4d6f18a38955bfd6minfrin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick * SUCH DAMAGE.
185aa71728867671e105178b4c66fbc22b65ae26sf * ====================================================================
43c3e6a4b559b76b750c245ee95e2782c15b4296jim * This software consists of voluntary contributions made by many
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * individuals on behalf of the Apache Software Foundation. For more
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * information on the Apache Software Foundation, please see
185aa71728867671e105178b4c66fbc22b65ae26sf * Portions of this software are based upon public domain software
43c3e6a4b559b76b750c245ee95e2782c15b4296jim * originally written at the National Center for Supercomputing Applications,
43c3e6a4b559b76b750c245ee95e2782c15b4296jim * University of Illinois, Urbana-Champaign.
31360b9fcb08b728b4ca0bf80720ebb589ad7ab8wrowe * Actual definitions of config globals
0c9166d0186cf0e1ad397025f730ae6967f44ce6jortonstatic int threads_to_start = 0; /* Worker threads per child */
0c9166d0186cf0e1ad397025f730ae6967f44ce6jortonstatic int min_spare_threads = 0;
5c5130fbb9d7aa3df3b908a19f1a358f45e25cbestoddardstatic int max_threads = 0;
1715880355ef7f574cae2e8f973411b51acededeylavicstatic int workers_may_exit = 0;
5c5130fbb9d7aa3df3b908a19f1a358f45e25cbestoddardstatic int num_listenfds = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The max child slot ever assigned, preserved across restarts. Necessary
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * to deal with NumServers changes across SIGWINCH restarts. We use this
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowe * value to optimize routines that have to scan the entire child table.
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe * XXX - It might not be worth keeping this code in. There aren't very
e95f5a6ebefb83d0e8a82cbc4db7d354957a817dben * many child processes in this MPM.
f05787953018140838ad51456c86c965d6a86267jim/* *Non*-shared http_main globals... */
static int one_process = 0;
#ifdef DEBUG_SIGSTOP
int raise_sigstop_flags;
static int child_num;
static int worker_thread_count;
static int idle_thread_count;
#ifdef NO_SERIALIZED_ACCEPT
static const char *lock_fname;
return (ap_server_conf);
return ap_max_daemons_limit;
if (pchild) {
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
case SIGTERM:
case SIGHUP:
case SIGUSR1:
case SIGKILL:
#ifdef SYS_SIGLIST
#ifdef WCOREDUMP
#ifdef WCOREDUMP
int num_listeners = 0;
return num_listeners;
static void sock_disable_nagle(int s)
int ap_graceful_stop_signalled(void)
return is_graceful;
int csd;
conn_id);
static void *worker_thread(void *);
static int start_thread(void)
static int reported = 0;
if (!reported) {
static void check_pipe_of_death(void)
if (!workers_may_exit) {
int ret;
char pipe_read_char;
int srv;
for(n=0 ; n <= num_listenfds ; ++n)
while (!workers_may_exit) {
if (workers_may_exit) break;
if (!thread_just_started) {
thread_just_started = 0;
if (workers_may_exit) {
!= APR_SUCCESS) {
while (!workers_may_exit) {
if (workers_may_exit) break;
goto got_fd;
curr_pollfd++;
goto got_fd;
if (!workers_may_exit) {
!= APR_SUCCESS) {
if (!start_thread()) {
!= APR_SUCCESS) {
if (worker_thread_count == 0) {
return NULL;
int signal_received;
pchild));
if (unixd_setup_child()) {
#ifdef SIGPROCMASK_SETS_THREAD_MASK
worker_thread_count = 0;
for (i = 0; i < max_threads; i++) {
worker_thread_free_ids[i] = i;
for (i=0; i < threads_to_start; i++) {
if (!start_thread()) {
switch (signal_received) {
case SIGTERM:
case SIGINT:
int pid;
if (one_process) {
set_signals();
if (!pid) {
#ifdef AIX_BIND_PROCESSOR
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;
for (i = 0; i < ap_max_daemons_limit; ++i) {
child_slot = i;
for (j = 0; j < HARD_THREAD_LIMIT; j++) {
if (child_slot >= 0) {
#ifdef APR_HAS_OTHER_CHILD
else if (is_graceful) {
else if (remaining_children_to_start) {
ap_server_conf = s;
!= APR_SUCCESS) {
ap_server_conf = s;
my_pid);
if (!is_graceful) {
if (!is_graceful) {
for (i = 0; i < HARD_SERVER_LIMIT; i++) {
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;) {
static int restart_num = 0;
is_graceful = 0;
if (!one_process) {
ap_detach();
static void dexter_hooks(void)
one_process = 0;
return err;
return NULL;
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;
return err;
return NULL;
const char *fname;
return err;
return NULL;
{ NULL }