prefork.c revision 5973c2eef790195891489772713c11c3bf87029c
85816edcdb4137f90186cb437949a4dbcbf46ab5jim/* ====================================================================
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * The Apache Software License, Version 1.1
182f52731de370a91a76b08ff73a43d1ea7bb4e8nd * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * reserved.
031b91a62d25106ae69d4693475c79618dd5e884fielding * Redistribution and use in source and binary forms, with or without
031b91a62d25106ae69d4693475c79618dd5e884fielding * modification, are permitted provided that the following conditions
031b91a62d25106ae69d4693475c79618dd5e884fielding * 1. Redistributions of source code must retain the above copyright
031b91a62d25106ae69d4693475c79618dd5e884fielding * notice, this list of conditions and the following disclaimer.
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * 2. Redistributions in binary form must reproduce the above copyright
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * notice, this list of conditions and the following disclaimer in
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * the documentation and/or other materials provided with the
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * distribution.
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * 3. The end-user documentation included with the redistribution,
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * if any, must include the following acknowledgment:
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * "This product includes software developed by the
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * Apache Software Foundation (http://www.apache.org/)."
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * Alternately, this acknowledgment may appear in the software itself,
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * if and wherever such third-party acknowledgments normally appear.
ee5db395bc3723609919edfa96af387eea37c491jim * 4. The names "Apache" and "Apache Software Foundation" must
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * not be used to endorse or promote products derived from this
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * software without prior written permission. For written
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * permission, please contact apache@apache.org.
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * 5. Products derived from this software may not be called "Apache",
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * nor may "Apache" appear in their name, without prior written
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * permission of the Apache Software Foundation.
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ee5db395bc3723609919edfa96af387eea37c491jim * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dfa73086d0dbdce20b24181dd127f5dd952367d4sf * SUCH DAMAGE.
dfa73086d0dbdce20b24181dd127f5dd952367d4sf * ====================================================================
dfa73086d0dbdce20b24181dd127f5dd952367d4sf * This software consists of voluntary contributions made by many
dfa73086d0dbdce20b24181dd127f5dd952367d4sf * individuals on behalf of the Apache Software Foundation. For more
dfa73086d0dbdce20b24181dd127f5dd952367d4sf * information on the Apache Software Foundation, please see
dfa73086d0dbdce20b24181dd127f5dd952367d4sf * Portions of this software are based upon public domain software
7087ccb939b4146f850f4d482fd8ab13de6335dchumbedooh * originally written at the National Center for Supercomputing Applications,
85816edcdb4137f90186cb437949a4dbcbf46ab5jim * University of Illinois, Urbana-Champaign.
ee5db395bc3723609919edfa96af387eea37c491jim#include <bstring.h> /* for IRIX, FD_SET calls bzero() */
#ifdef HAVE_SYS_PROCESSOR_H
#include <signal.h>
#ifndef DEFAULT_SERVER_LIMIT
#ifndef MAX_SERVER_LIMIT
#ifndef HARD_THREAD_LIMIT
static int ap_daemons_to_start=0;
static int ap_daemons_min_free=0;
static int ap_daemons_max_free=0;
static int first_server_limit;
static int changed_limit_at_restart;
static int one_process = 0;
#ifndef MULTITHREAD
static int my_child_num;
#ifdef TPF
int tpf_child = 0;
static int die_now = 0;
#ifdef GPROF
* configure in httpd.conf:
* GprofDir $RuntimeDir/ -> $ServerRoot/$RuntimeDir/gmon.out
* GprofDir $RuntimeDir/% -> $ServerRoot/$RuntimeDir/gprof.$pid/gmon.out
static void chdir_for_gprof(void)
const char *use_dir;
if(dir) {
#define chdir_for_gprof()
#define ap_check_signals()
if (pchild) {
static void accept_mutex_on(void)
if (ap_my_generation !=
clean_child_exit(0);
static void accept_mutex_off(void)
if (ap_my_generation !=
switch(query_code){
case AP_MPMQ_MAX_DAEMON_USED:
return APR_SUCCESS;
case AP_MPMQ_IS_THREADED:
return APR_SUCCESS;
case AP_MPMQ_IS_FORKED:
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
case AP_MPMQ_MAX_THREADS:
*result = 0;
return APR_SUCCESS;
return APR_SUCCESS;
*result = 0;
return APR_SUCCESS;
return APR_SUCCESS;
*result = 0;
return APR_SUCCESS;
return APR_SUCCESS;
case AP_MPMQ_MAX_DAEMONS:
return APR_SUCCESS;
return APR_ENOTIMPL;
#if defined(NEED_WAITPID)
int n, pid;
for (n = 0; n < ap_max_daemons_limit; ++n) {
*exitcode = 0;
return(pid);
0, ap_server_conf,
clean_child_exit(0);
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
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
ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")");
if (!one_process) {
#ifdef SIGBUS
#ifdef SIGABORT
#ifdef SIGABRT
#ifdef SIGILL
#ifdef SIGXCPU
#ifdef SIGXFSZ
#ifdef SIGHUP
#ifdef AP_SIG_GRACEFUL
#ifdef SIGPIPE
static int requests_this_child;
static int num_listensocks = 0;
int ap_graceful_stop_signalled(void)
int offset;
void *csd;
requests_this_child = 0;
if (unixd_setup_child()) {
for (i = 0; i < num_listensocks; i++) {
while (!die_now) {
if ((ap_max_requests_per_child > 0
clean_child_exit(0);
offset = 0;
apr_int32_t n;
curr_pollfd++;
curr_pollfd = 0;
goto got_fd;
current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_child_num, sbh, bucket_alloc);
if (current_conn) {
else if (ap_my_generation !=
clean_child_exit(0);
int pid;
if (one_process) {
#ifdef SIGQUIT
#ifdef _OSD_POSIX
if (!pid) {
#ifdef HAVE_BINDPROCESSOR
#ifndef MAX_SPAWN_RATE
static int hold_off_on_exponential_spawning;
int to_kill;
int idle_count;
int free_length;
int last_non_dead;
int total_non_dead;
free_length = 0;
idle_count = 0;
total_non_dead = 0;
for (i = 0; i < ap_daemons_limit; ++i) {
int status;
++free_length;
++ idle_count;
to_kill = i;
last_non_dead = i;
if (free_length == 0) {
static int reported = 0;
if (!reported) {
"to increase StartServers, or Min/MaxSpareServers), "
for (i = 0; i < free_length; ++i) {
#ifdef TPF
int index;
if (changed_limit_at_restart) {
if (!is_graceful) {
set_signals();
if (one_process) {
if (!is_graceful) {
int child_slot;
if (child_slot >= 0) {
else if (remaining_children_to_start
else if (is_graceful) {
0, ap_server_conf,
else if (remaining_children_to_start) {
#ifdef TPF
if (shutdown_pending) {
0, ap_server_conf,
if (one_process) {
if (is_graceful) {
pconf = p;
ap_server_conf = s;
return DONE;
return DONE;
return OK;
static int restart_num = 0;
if (debug) {
no_detach = 0;
is_graceful = 0;
return HTTP_INTERNAL_SERVER_ERROR;
ap_extended_status = 0;
return OK;
#ifdef AUX3
(void) set42sig();
return err;
return NULL;
return err;
if (ap_daemons_min_free <= 0) {
return NULL;
return err;
return NULL;
return err;
return NULL;
int tmp_server_limit;
return err;
if (first_server_limit &&
return NULL;
return NULL;
{ NULL }