prefork.c revision 4508be63cded849dbe65cf4b303b8a27d71f8e0d
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * are met:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * <http://www.apache.org/>.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Portions of this software are based upon public domain software
f4c310fd2555c6faca1f980f00b161eadb089023gstein * originally written at the National Center for Supercomputing Applications,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * University of Illinois, Urbana-Champaign.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * httpd.c: simple http daemon for answering WWW file requests
952023a04a2f9d51553babd9094fb857f1c97548trawick *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * 03-21-93 Rob McCool wrote original code (up to NCSA HTTPd 1.3)
1b21d7b3d97def358b2e923655edeb16613a1c31gstein *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * 03-06-95 blong
f4c310fd2555c6faca1f980f00b161eadb089023gstein * changed server number for child-alone processes to 0 and changed name
f4c310fd2555c6faca1f980f00b161eadb089023gstein * of processes
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 03-10-95 blong
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Added numerous speed hacks proposed by Robert S. Thau (rst@ai.mit.edu)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * including set group before fork, and call gettime before to fork
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to set up libraries.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * 04-14-95 rst / rh
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * Brandon's code snarfed from NCSA 1.4, but tinkered to work with the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Apache server, and also to have child processes do accept() directly.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * April-July '95 rst
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Extensive rework for Apache.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* TODO: this is a cobbled together prefork MPM example... it should mostly
f4c310fd2555c6faca1f980f00b161eadb089023gstein * TODO: behave like apache-1.3... here's a short list of things I think
f4c310fd2555c6faca1f980f00b161eadb089023gstein * TODO: need cleaning up still:
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_portable.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_strings.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "apr_thread_proc.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "apr_signal.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define APR_WANT_STDIO
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#define APR_WANT_STRFUNC
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_want.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAVE_UNISTD_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <unistd.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAVE_SYS_TYPES_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <sys/types.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#define CORE_PRIVATE
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "httpd.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "mpm_default.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_main.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_log.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_config.h"
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#include "http_core.h" /* for get_remote_host */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_connection.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "scoreboard.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_mpm.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "unixd.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "mpm_common.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "ap_listen.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "ap_mmn.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_BSTRING_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <bstring.h> /* for IRIX, FD_SET calls bzero() */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_TIME_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <time.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_SYS_PROCESSOR_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <sys/processor.h> /* for bindprocessor() */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <signal.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <sys/times.h>
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* config globals */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_threads_per_child=0; /* Worker threads per child */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int ap_max_requests_per_child=0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *ap_pid_fname=NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_lock_t *accept_lock;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowestatic const char *ap_lock_fname;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowestatic int ap_daemons_to_start=0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int ap_daemons_min_free=0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int ap_daemons_max_free=0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int ap_daemons_limit=0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_pod_t *pod;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe/*
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * The max child slot ever assigned, preserved across restarts. Necessary
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to deal with MaxClients changes across SIGWINCH restarts. We use this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * value to optimize routines that have to scan the entire scoreboard.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_max_daemons_limit = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinserver_rec *ap_server_conf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinchar ap_coredump_dir[MAX_STRING_LEN];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* *Non*-shared http_main globals... */
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowestatic apr_socket_t *sd;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic fd_set listenfds;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int listenmaxfd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* one_process --- debugging mode variable; can be set from the command line
f4c310fd2555c6faca1f980f00b161eadb089023gstein * with the -X flag. If set, this gets you the child_main loop running
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in the process which originally started up (no detach, no make_child),
f4c310fd2555c6faca1f980f00b161eadb089023gstein * which is a pretty nice debugging environment. (You'll get a SIGHUP
f4c310fd2555c6faca1f980f00b161eadb089023gstein * early in standalone_main; just continue through. This is the server
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * trying to kill off any child processes which it might have lying
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * around --- Apache doesn't keep track of their pids, it just sends
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * SIGHUP to the process group, ignoring it in the root process.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Continue through and you'll be fine.).
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int one_process = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_pool_t *pconf; /* Pool for config stuff */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_pool_t *pchild; /* Pool for httpd child stuff */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic pid_t ap_my_pid; /* it seems silly to call getpid all the time */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifndef MULTITHREAD
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int my_child_num;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef TPF
48f35e10f195dd594d75738fc536bb885eda537cgsteinint tpf_child = 0;
48f35e10f195dd594d75738fc536bb885eda537cgsteinchar tpf_server_name[INETD_SERVNAME_LENGTH+1];
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* TPF */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint die_now = 0;
91644a5f4d3e992dc208304b50e80bbb236fca89trawick
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm#ifdef GPROF
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * change directory for gprof to plop the gmon.out file
f4c310fd2555c6faca1f980f00b161eadb089023gstein * configure in httpd.conf:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * GprofDir logs/ -> $ServerRoot/logs/gmon.out
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm * GprofDir logs/% -> $ServerRoot/logs/gprof.$pid/gmon.out
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void chdir_for_gprof(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_server_config *sconf =
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_get_module_config(ap_server_conf->module_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *dir = sconf->gprof_dir;
48f35e10f195dd594d75738fc536bb885eda537cgstein const char *use_dir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if(dir) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char buf[512];
f4c310fd2555c6faca1f980f00b161eadb089023gstein int len = strlen(sconf->gprof_dir) - 1;
48f35e10f195dd594d75738fc536bb885eda537cgstein if(*(dir + len) == '%') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein dir[len] = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_snprintf(buf, sizeof(buf), "%sgprof.%d", dir, (int)getpid());
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein use_dir = ap_server_root_relative(pconf, buf[0] ? buf : dir);
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = apr_dir_make(use_dir, 0755, pconf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "gprof: error creating directory %s", dir);
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein else {
48f35e10f195dd594d75738fc536bb885eda537cgstein use_dir = ap_server_root_relative(pconf, "logs");
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein chdir(dir);
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein#else
48f35e10f195dd594d75738fc536bb885eda537cgstein#define chdir_for_gprof()
48f35e10f195dd594d75738fc536bb885eda537cgstein#endif
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein/* XXX - I don't know if TPF will ever use this module or not, so leave
48f35e10f195dd594d75738fc536bb885eda537cgstein * the ap_check_signals calls in but disable them - manoj */
48f35e10f195dd594d75738fc536bb885eda537cgstein#define ap_check_signals()
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein/* a clean exit from a child with proper cleanup */
864c5615d55b8ebbde24e72043f6325741335a74fieldingstatic void clean_child_exit(int code) __attribute__ ((noreturn));
48f35e10f195dd594d75738fc536bb885eda537cgsteinstatic void clean_child_exit(int code)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
48f35e10f195dd594d75738fc536bb885eda537cgstein if (pchild) {
48f35e10f195dd594d75738fc536bb885eda537cgstein apr_pool_destroy(pchild);
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_mpm_pod_close(pod);
48f35e10f195dd594d75738fc536bb885eda537cgstein chdir_for_gprof();
48f35e10f195dd594d75738fc536bb885eda537cgstein exit(code);
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgsteinstatic void expand_lock_fname(apr_pool_t *p)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
48f35e10f195dd594d75738fc536bb885eda537cgstein /* XXXX possibly bogus cast */
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_lock_fname = apr_psprintf(p, "%s.%lu",
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_server_root_relative(p, ap_lock_fname), (unsigned long)getpid());
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein/* Initialize mutex lock.
48f35e10f195dd594d75738fc536bb885eda537cgstein * Done by each child at its birth
48f35e10f195dd594d75738fc536bb885eda537cgstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void accept_mutex_child_init(apr_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_lock_child_init(&accept_lock, ap_lock_fname, p);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "couldn't do child init for accept mutex");
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(APEXIT_CHILDINIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Initialize mutex lock.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Must be safe to call this on a restart.
48f35e10f195dd594d75738fc536bb885eda537cgstein */
48f35e10f195dd594d75738fc536bb885eda537cgsteinstatic void accept_mutex_init(apr_pool_t *p)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein expand_lock_fname(p);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_lock_create(&accept_lock, APR_MUTEX, APR_CROSS_PROCESS, ap_lock_fname, p);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "couldn't create accept mutex");
f4c310fd2555c6faca1f980f00b161eadb089023gstein exit(APEXIT_INIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void accept_mutex_on(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv = apr_lock_acquire(accept_lock);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "couldn't grab the accept mutex");
f4c310fd2555c6faca1f980f00b161eadb089023gstein exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void accept_mutex_off(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv = apr_lock_release(accept_lock);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "couldn't release the accept mutex");
f958dac1550254a59b45f4655138bb34dad5e76egstein exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* On some architectures it's safe to do unserialized accept()s in the single
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Listen case. But it's never safe to do it in the case where there's
f4c310fd2555c6faca1f980f00b161eadb089023gstein * multiple Listen statements. Define SINGLE_LISTEN_UNSERIALIZED_ACCEPT
f4c310fd2555c6faca1f980f00b161eadb089023gstein * when it's safe in the single Listen case.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next) {stmt;}} while(0)
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define SAFE_ACCEPT(stmt) do {stmt;} while(0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch(query_code){
f4c310fd2555c6faca1f980f00b161eadb089023gstein case AP_MPMQ_MAX_DAEMONS:
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein *result = ap_daemons_limit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_SUCCESS;
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein case AP_MPMQ_IS_THREADED:
f4c310fd2555c6faca1f980f00b161eadb089023gstein *result = AP_MPMQ_NOT_SUPPORTED;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_SUCCESS;
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein case AP_MPMQ_IS_FORKED:
f4c310fd2555c6faca1f980f00b161eadb089023gstein *result = AP_MPMQ_DYNAMIC;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_SUCCESS;
f4c310fd2555c6faca1f980f00b161eadb089023gstein case AP_MPMQ_HARD_LIMIT_DAEMONS:
f4c310fd2555c6faca1f980f00b161eadb089023gstein *result = HARD_SERVER_LIMIT;
f39230a531b23d94f86a087963299bbe2e431a4agstein return APR_SUCCESS;
f39230a531b23d94f86a087963299bbe2e431a4agstein case AP_MPMQ_HARD_LIMIT_THREADS:
f39230a531b23d94f86a087963299bbe2e431a4agstein *result = HARD_THREAD_LIMIT;
f39230a531b23d94f86a087963299bbe2e431a4agstein return APR_SUCCESS;
f39230a531b23d94f86a087963299bbe2e431a4agstein case AP_MPMQ_MAX_THREADS:
f39230a531b23d94f86a087963299bbe2e431a4agstein *result = 0;
f39230a531b23d94f86a087963299bbe2e431a4agstein return APR_SUCCESS;
f39230a531b23d94f86a087963299bbe2e431a4agstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein return APR_ENOTIMPL;
f39230a531b23d94f86a087963299bbe2e431a4agstein}
1e2133fe37e6cbcd683233057ef62236bc8e5826trawick
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein#if defined(NEED_WAITPID)
f39230a531b23d94f86a087963299bbe2e431a4agstein/*
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein Systems without a real waitpid sometimes lose a child's exit while waiting
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein for another. Search through the scoreboard for missing children.
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gsteinint reap_children(apr_wait_t *status)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein int n, pid;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein for (n = 0; n < ap_max_daemons_limit; ++n) {
f39230a531b23d94f86a087963299bbe2e431a4agstein ap_sync_scoreboard_image();
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (ap_scoreboard_image->servers[n][0].status != SERVER_DEAD &&
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) {
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ap_update_child_status(AP_CHILD_THREAD_FROM_ID(n), SERVER_DEAD, NULL);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein /* just mark it as having a successful exit status */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein memset(status, 0, sizeof(apr_wait_t));
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return(pid);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein }
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein }
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return 0;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein}
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein#endif
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein/* handle all varieties of core dumping signals */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gsteinstatic void sig_coredump(int sig)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein{
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein chdir(ap_coredump_dir);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein apr_signal(sig, SIG_DFL);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein kill(getpid(), sig);
f39230a531b23d94f86a087963299bbe2e431a4agstein /* At this point we've got sig blocked, because we're still inside
f39230a531b23d94f86a087963299bbe2e431a4agstein * the signal handler. When we leave the signal handler it will
f39230a531b23d94f86a087963299bbe2e431a4agstein * be unblocked, and we'll take the signal... and coredump or whatever
f39230a531b23d94f86a087963299bbe2e431a4agstein * is appropriate for this particular Unix. In addition the parent
f39230a531b23d94f86a087963299bbe2e431a4agstein * will see the real signal we received -- whereas if we called
f39230a531b23d94f86a087963299bbe2e431a4agstein * abort() here, the parent would only see SIGABRT.
f39230a531b23d94f86a087963299bbe2e431a4agstein */
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein/*****************************************************************
f39230a531b23d94f86a087963299bbe2e431a4agstein * Connection structures and accounting...
f39230a531b23d94f86a087963299bbe2e431a4agstein */
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic void just_die(int sig)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein clean_child_exit(0);
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic void please_die_gracefully(int sig)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein /* clean_child_exit(0); */
f39230a531b23d94f86a087963299bbe2e431a4agstein die_now = 1;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein/* volatile just in case */
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int volatile shutdown_pending;
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int volatile restart_pending;
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int volatile is_graceful;
f39230a531b23d94f86a087963299bbe2e431a4agsteinap_generation_t volatile ap_my_generation=0;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic void sig_term(int sig)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein if (shutdown_pending == 1) {
f39230a531b23d94f86a087963299bbe2e431a4agstein /* Um, is this _probably_ not an error, if the user has
f39230a531b23d94f86a087963299bbe2e431a4agstein * tried to do a shutdown twice quickly, so we won't
f39230a531b23d94f86a087963299bbe2e431a4agstein * worry about reporting it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein shutdown_pending = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* restart() is the signal handler for SIGHUP and SIGWINCH
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in the parent process, unless running in ONE_PROCESS mode
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void restart(int sig)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (restart_pending == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Probably not an error - don't bother reporting it */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein restart_pending = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((is_graceful = (sig == SIGWINCH))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_kill(pconf, NULL, ap_cleanup_scoreboard);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void set_signals(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifndef NO_USE_SIGACTION
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sigaction sa;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigemptyset(&sa.sa_mask);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = sig_coredump;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(SA_ONESHOT)
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = SA_ONESHOT;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#elif defined(SA_RESETHAND)
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = SA_RESETHAND;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGSEGV, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGSEGV)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGBUS
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGBUS, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGBUS)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABORT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGABORT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABORT)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABRT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGABRT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABRT)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGILL
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGILL, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGILL)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = 0;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = sig_term;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGTERM, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGINT
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (sigaction(SIGINT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXCPU
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = SIG_DFL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGXCPU, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXFSZ
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = SIG_DFL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGXFSZ, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPIPE
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = SIG_IGN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGPIPE, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* we want to ignore HUPs and WINCH while we're busy processing one */
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigaddset(&sa.sa_mask, SIGHUP);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigaddset(&sa.sa_mask, SIGWINCH);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = restart;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGHUP, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGWINCH, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGWINCH)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGSEGV, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGBUS
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGBUS, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGBUS */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABORT
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGABORT, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGABORT */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABRT
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGABRT, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGABRT */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGILL
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGILL, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGILL */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXCPU
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGXCPU, SIG_DFL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGXCPU */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXFSZ
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGXFSZ, SIG_DFL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGXFSZ */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGTERM, sig_term);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGHUP
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGHUP, restart);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGHUP */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGWINCH
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGWINCH, restart);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGWINCH */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPIPE
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGPIPE, SIG_IGN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGPIPE */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Child process main loop.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The following vars are static to avoid getting clobbered by longjmp();
f4c310fd2555c6faca1f980f00b161eadb089023gstein * they are really private to child_main.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int srv;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_socket_t *csd;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int requests_this_child;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic fd_set main_fds;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_graceful_stop_signalled(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* not ever called anymore... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougmstatic void child_main(int child_num_arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *last_lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *first_lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_t *ptrans;
f4c310fd2555c6faca1f980f00b161eadb089023gstein conn_rec *current_conn;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_status_t stat = APR_EINIT;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int sockdes;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein my_child_num = child_num_arg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_my_pid = getpid();
f4c310fd2555c6faca1f980f00b161eadb089023gstein csd = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein requests_this_child = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein last_lr = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Get a sub context for global allocations in this child, so that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we can have cleanups occur when the child exits.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_create(&pchild, pconf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_create(&ptrans, pchild);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* needs to be done before we switch UIDs so we have permissions */
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm reopen_scoreboard(pchild);
f4c310fd2555c6faca1f980f00b161eadb089023gstein SAFE_ACCEPT(accept_mutex_child_init(pchild));
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (unixd_setup_child()) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_child_init(pchild, ap_server_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(my_child_num), SERVER_READY, (request_rec *) NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!die_now) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * (Re)initialize this child to a pre-connection state.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein current_conn = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_clear(ptrans);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((ap_max_requests_per_child > 0
f4c310fd2555c6faca1f980f00b161eadb089023gstein && requests_this_child++ >= ap_max_requests_per_child)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(my_child_num), SERVER_READY, (request_rec *) NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Wait for an acceptable connection to arrive.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Lock around "accept", if necessary */
f4c310fd2555c6faca1f980f00b161eadb089023gstein SAFE_ACCEPT(accept_mutex_on());
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (;;) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_listeners->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* more than one socket */
f4c310fd2555c6faca1f980f00b161eadb089023gstein memcpy(&main_fds, &listenfds, sizeof(fd_set));
f4c310fd2555c6faca1f980f00b161eadb089023gstein srv = select(listenmaxfd + 1, &main_fds, NULL, NULL, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (srv < 0 && errno != EINTR) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Single Unix documents select as returning errnos
f4c310fd2555c6faca1f980f00b161eadb089023gstein * EBADF, EINTR, and EINVAL... and in none of those
f4c310fd2555c6faca1f980f00b161eadb089023gstein * cases does it make sense to continue. In fact
f4c310fd2555c6faca1f980f00b161eadb089023gstein * on Linux 2.0.x we seem to end up with EFAULT
f4c310fd2555c6faca1f980f00b161eadb089023gstein * occasionally, and we'd loop forever due to it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf, "select: (listen)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (srv <= 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we remember the last_lr we searched last time around so that
f4c310fd2555c6faca1f980f00b161eadb089023gstein we don't end up starving any particular listening socket */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (last_lr == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein lr = ap_listeners;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein lr = last_lr->next;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!lr)
f4c310fd2555c6faca1f980f00b161eadb089023gstein lr = ap_listeners;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein first_lr=lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein do {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_os_sock_get(&sockdes, lr->sd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (FD_ISSET(sockdes, &main_fds))
f4c310fd2555c6faca1f980f00b161eadb089023gstein goto got_listener;
f4c310fd2555c6faca1f980f00b161eadb089023gstein lr = lr->next;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!lr)
f4c310fd2555c6faca1f980f00b161eadb089023gstein lr = ap_listeners;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (lr != first_lr);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* FIXME: if we get here, something bad has happened, and we're
f4c310fd2555c6faca1f980f00b161eadb089023gstein probably gonna spin forever.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein got_listener:
f4c310fd2555c6faca1f980f00b161eadb089023gstein last_lr = lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein sd = lr->sd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* only one socket, just pretend we did the other stuff */
f4c310fd2555c6faca1f980f00b161eadb089023gstein sd = ap_listeners->sd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* if we accept() something we don't want to die, so we have to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * defer the exit
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (;;) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (die_now) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we didn't get a socket, and we were told to die */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein stat = apr_accept(&csd, sd, ptrans);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* In reality, this could be done later, but to keep it
f4c310fd2555c6faca1f980f00b161eadb089023gstein * consistent with MPMs that have a thread race-condition,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we will do it here.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_mpm_pod_check(pod)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein die_now = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (stat == APR_SUCCESS || !APR_STATUS_IS_EINTR(stat))
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (stat == APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein break; /* We have a socket ready for reading */
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* TODO: this accept result handling stuff should be abstracted...
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * it's already out of date between the various unix mpms
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Our old behaviour here was to continue after accept()
f4c310fd2555c6faca1f980f00b161eadb089023gstein * errors. But this leads us into lots of troubles
f4c310fd2555c6faca1f980f00b161eadb089023gstein * because most of the errors are quite fatal. For
f4c310fd2555c6faca1f980f00b161eadb089023gstein * example, EMFILE can be caused by slow descriptor
f4c310fd2555c6faca1f980f00b161eadb089023gstein * leaks (say in a 3rd party module, or libc). It's
f4c310fd2555c6faca1f980f00b161eadb089023gstein * foolish for us to continue after an EMFILE. We also
f4c310fd2555c6faca1f980f00b161eadb089023gstein * seem to tickle kernel bugs on some platforms which
f4c310fd2555c6faca1f980f00b161eadb089023gstein * lead to never-ending loops here. So it seems best
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to just exit in most cases.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (stat) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef EPROTO
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* EPROTO on certain older kernels really means
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ECONNABORTED, so we need to ignore it for them.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * See discussion in new-httpd archives nh.9701
f4c310fd2555c6faca1f980f00b161eadb089023gstein * search for EPROTO.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Also see nh.9603, search for EPROTO:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * There is potentially a bug in Solaris 2.x x<6,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and other boxes that implement tcp sockets in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * userland (i.e. on top of STREAMS). On these
f4c310fd2555c6faca1f980f00b161eadb089023gstein * systems, EPROTO can actually result in a fatal
f4c310fd2555c6faca1f980f00b161eadb089023gstein * loop. See PR#981 for example. It's hard to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * handle both uses of EPROTO.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein case EPROTO:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef ECONNABORTED
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ECONNABORTED:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Linux generates the rest of these, other tcp
f4c310fd2555c6faca1f980f00b161eadb089023gstein * stacks (i.e. bsd) tend to hide them behind
f4c310fd2555c6faca1f980f00b161eadb089023gstein * getsockopt() interfaces. They occur when
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the net goes sour or the client disconnects
f4c310fd2555c6faca1f980f00b161eadb089023gstein * after the three-way handshake has been done
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in the kernel but before userland has picked
f4c310fd2555c6faca1f980f00b161eadb089023gstein * up the socket.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef ECONNRESET
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ECONNRESET:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef ETIMEDOUT
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ETIMEDOUT:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef EHOSTUNREACH
f4c310fd2555c6faca1f980f00b161eadb089023gstein case EHOSTUNREACH:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef ENETUNREACH
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ENETUNREACH:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef ENETDOWN
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ENETDOWN:
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * When the network layer has been shut down, there
f4c310fd2555c6faca1f980f00b161eadb089023gstein * is not much use in simply exiting: the parent
f4c310fd2555c6faca1f980f00b161eadb089023gstein * would simply re-create us (and we'd fail again).
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Use the CHILDFATAL code to tear the server down.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * @@@ Martin's idea for possible improvement:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * A different approach would be to define
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a new APEXIT_NETDOWN exit code, the reception
f4c310fd2555c6faca1f980f00b161eadb089023gstein * of which would make the parent shutdown all
f4c310fd2555c6faca1f980f00b161eadb089023gstein * children, then idle-loop until it detected that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the network is up again, and restart the children.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Ben Hyde noted that temporary ENETDOWN situations
f4c310fd2555c6faca1f980f00b161eadb089023gstein * occur in mobile IP.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, stat, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "apr_accept: giving up.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /*ENETDOWN*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef TPF
f4c310fd2555c6faca1f980f00b161eadb089023gstein case EINACT:
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, stat, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "offload device inactive");
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe clean_child_exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein default:
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "select/accept error (%d)", stat);
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein default:
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, stat, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "apr_accept: (client socket)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (die_now) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We now have a connection, so set it up with the appropriate
f4c310fd2555c6faca1f980f00b161eadb089023gstein * socket options, file descriptors, and read/write buffers.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_os_sock_get(&sockdes, csd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sockdes >= FD_SETSIZE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "new file descriptor %d is too large; you probably need "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "to rebuild Apache with a larger FD_SETSIZE "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "(currently %d)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein sockdes, FD_SETSIZE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_socket_close(csd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef TPF
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sockdes == 0) { /* 0 is invalid socket for TPF */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sock_disable_nagle(csd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein current_conn = ap_new_connection(ptrans, ap_server_conf, csd,
f4c310fd2555c6faca1f980f00b161eadb089023gstein my_child_num);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (current_conn) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_process_connection(current_conn);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_lingering_close(current_conn);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int make_child(server_rec *s, int slot)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int pid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (slot + 1 > ap_max_daemons_limit) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_daemons_limit = slot + 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGHUP, please_die_gracefully);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGINT, please_die_gracefully);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGQUIT
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGQUIT, SIG_DFL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGTERM, just_die);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->parent[slot].process_status = SB_WORKING;
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_main(slot);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(slot), SERVER_STARTING, (request_rec *) NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef _OSD_POSIX
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* BS2000 requires a "special" version of fork() before a setuid() call */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((pid = os_fork(unixd_config.user_name)) == -1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#elif defined(TPF)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((pid = os_fork(s, slot)) == -1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((pid = fork()) == -1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "fork: Unable to fork new process");
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* fork didn't succeed. Fix the scoreboard or else
f4c310fd2555c6faca1f980f00b161eadb089023gstein * it will say SERVER_STARTING forever and ever
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(slot), SERVER_DEAD, (request_rec *) NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* In case system resources are maxxed out, we don't want
f4c310fd2555c6faca1f980f00b161eadb089023gstein Apache running away with the CPU trying to fork over and
f4c310fd2555c6faca1f980f00b161eadb089023gstein over and over again. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein sleep(10);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!pid) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_BINDPROCESSOR
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* by default AIX binds to a single processor
f4c310fd2555c6faca1f980f00b161eadb089023gstein * this bit unbinds children which will then bind to another cpu
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein int status = bindprocessor(BINDPROCESS, (int)getpid(),
f4c310fd2555c6faca1f980f00b161eadb089023gstein PROCESSOR_CLASS_ANY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status != OK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, errno,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf, "processor unbind failed %d", status);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein RAISE_SIGSTOP(MAKE_CHILD);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Disable the parent's signal handlers and set up proper handling in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the child.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGHUP, just_die);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGTERM, just_die);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The child process doesn't do anything for SIGWINCH. Instead, the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pod is used for signalling graceful restart.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGWINCH, SIG_IGN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->parent[slot].process_status = SB_WORKING;
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_main(slot);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->parent[slot].pid = pid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SCOREBOARD_FILE
f4c310fd2555c6faca1f980f00b161eadb089023gstein lseek(scoreboard_fd, XtOffsetOf(scoreboard, parent[slot]), 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein force_write(scoreboard_fd, &ap_scoreboard_image->parent[slot],
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(process_score));
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* start up a bunch of children */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void startup_children(int number_to_start)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; number_to_start && i < ap_daemons_limit; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image->servers[i][0].status != SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (make_child(ap_server_conf, i) < 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein --number_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * idle_spawn_rate is the number of children that will be spawned on the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * next maintenance cycle if there aren't enough idle servers. It is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
f4c310fd2555c6faca1f980f00b161eadb089023gstein * without the need to spawn.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int idle_spawn_rate = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifndef MAX_SPAWN_RATE
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define MAX_SPAWN_RATE (32)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int hold_off_on_exponential_spawning;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void perform_idle_server_maintenance(apr_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int to_kill;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int idle_count;
f4c310fd2555c6faca1f980f00b161eadb089023gstein worker_score *ws;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int free_length;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int free_slots[MAX_SPAWN_RATE];
f4c310fd2555c6faca1f980f00b161eadb089023gstein int last_non_dead;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int total_non_dead;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* initialize the free_list */
f4c310fd2555c6faca1f980f00b161eadb089023gstein free_length = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein to_kill = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_count = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein last_non_dead = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein total_non_dead = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < ap_daemons_limit; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (i >= ap_max_daemons_limit && free_length == idle_spawn_rate)
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws = &ap_scoreboard_image->servers[i][0];
f4c310fd2555c6faca1f980f00b161eadb089023gstein status = ws->status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* try to keep children numbers as low as possible */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (free_length < idle_spawn_rate) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein free_slots[free_length] = i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++free_length;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We consider a starting server as idle because we started it
f4c310fd2555c6faca1f980f00b161eadb089023gstein * at least a cycle ago, and if it still hasn't finished starting
f4c310fd2555c6faca1f980f00b161eadb089023gstein * then we're just going to swamp things worse by forking more.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * So we hopefully won't need to fork more if we count it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * This depends on the ordering of SERVER_READY and SERVER_STARTING.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status <= SERVER_READY) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++ idle_count;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* always kill the highest numbered child if we have to...
f4c310fd2555c6faca1f980f00b161eadb089023gstein * no really well thought out reason ... other than observing
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the server behaviour under linux where lower numbered children
f4c310fd2555c6faca1f980f00b161eadb089023gstein * tend to service more hits (and hence are more likely to have
f4c310fd2555c6faca1f980f00b161eadb089023gstein * their data in cpu caches).
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein to_kill = i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++total_non_dead;
f4c310fd2555c6faca1f980f00b161eadb089023gstein last_non_dead = i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_daemons_limit = last_non_dead + 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (idle_count > ap_daemons_max_free) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* kill off one child... we use SIGWINCH because that'll cause it to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * shut down gracefully, in case it happened to pick up a request
f4c310fd2555c6faca1f980f00b161eadb089023gstein * while we were counting
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_mpm_pod_signal(pod);
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_spawn_rate = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (idle_count < ap_daemons_min_free) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* terminate the free list */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (free_length == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* only report this condition once */
f4c310fd2555c6faca1f980f00b161eadb089023gstein static int reported = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!reported) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "server reached MaxClients setting, consider"
f4c310fd2555c6faca1f980f00b161eadb089023gstein " raising the MaxClients setting");
f4c310fd2555c6faca1f980f00b161eadb089023gstein reported = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_spawn_rate = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (idle_spawn_rate >= 8) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "server seems busy, (you may need "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "to increase StartServers, or Min/MaxSpareServers), "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "spawning %d children, there are %d idle, and "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%d total children", idle_spawn_rate,
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_count, total_non_dead);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < free_length; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef TPF
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (make_child(ap_server_conf, free_slots[i]) == -1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if(free_length == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein shutdown_pending = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "No active child processes: shutting down");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein make_child(ap_server_conf, free_slots[i]);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* TPF */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* the next time around we want to spawn twice as many if this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * wasn't good enough, but not if we've just done a graceful
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (hold_off_on_exponential_spawning) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein --hold_off_on_exponential_spawning;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (idle_spawn_rate < MAX_SPAWN_RATE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_spawn_rate *= 2;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_spawn_rate = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int setup_listeners(server_rec *s)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int sockdes;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_setup_listeners(s) < 1 ) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, 0, s,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "no listening sockets available, shutting down");
f4c310fd2555c6faca1f980f00b161eadb089023gstein return -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein listenmaxfd = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein FD_ZERO(&listenfds);
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (lr = ap_listeners; lr; lr = lr->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_os_sock_get(&sockdes, lr->sd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein FD_SET(sockdes, &listenfds);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sockdes > listenmaxfd) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein listenmaxfd = sockdes;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Executive routines.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int index;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int remaining_children_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein pconf = _pconf;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf = s;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_log_pid(pconf, ap_pid_fname);
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (setup_listeners(s)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((rv = ap_mpm_pod_open(pconf, &pod))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not open pipe-of-death.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein SAFE_ACCEPT(accept_mutex_init(pconf));
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_create_scoreboard(pconf, SB_SHARED);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SCOREBOARD_FILE
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_note_cleanups_for_fd(pconf, scoreboard_fd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein set_signals();
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_daemons_max_free < ap_daemons_min_free + 1) /* Don't thrash... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_max_free = ap_daemons_min_free + 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If we're doing a graceful_restart then we're going to see a lot
f4c310fd2555c6faca1f980f00b161eadb089023gstein * of children exiting immediately when we get into the main loop
f4c310fd2555c6faca1f980f00b161eadb089023gstein * below (because we just sent them SIGWINCH). This happens pretty
f4c310fd2555c6faca1f980f00b161eadb089023gstein * rapidly... and for each one that exits we'll start a new one until
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we reach at least daemons_min_free. But we may be permitted to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * start more than that, so we'll just keep track of how many we're
f4c310fd2555c6faca1f980f00b161eadb089023gstein * supposed to start up without the 1 second penalty between each fork.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein remaining_children_to_start = ap_daemons_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (remaining_children_to_start > ap_daemons_limit) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein remaining_children_to_start = ap_daemons_limit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein startup_children(remaining_children_to_start);
f4c310fd2555c6faca1f980f00b161eadb089023gstein remaining_children_to_start = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* give the system some time to recover before kicking into
f4c310fd2555c6faca1f980f00b161eadb089023gstein * exponential mode */
f4c310fd2555c6faca1f980f00b161eadb089023gstein hold_off_on_exponential_spawning = 10;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s configured -- resuming normal operations",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_get_server_version());
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Server built: %s", ap_get_server_built());
f4c310fd2555c6faca1f980f00b161eadb089023gstein restart_pending = shutdown_pending = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!restart_pending && !shutdown_pending) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int child_slot;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_wait_t status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* this is a memory leak, but I'll fix it later. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_proc_t pid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_wait_or_timeout(&status, &pid, pconf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: if it takes longer than 1 second for all our children
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to start up and get into IDLE state then we may spawn an
f4c310fd2555c6faca1f980f00b161eadb089023gstein * extra child
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (pid.pid != -1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_process_child_status(&pid, status);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* non-fatal death... note that it's gone in the scoreboard. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_slot = find_child_by_pid(&pid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (child_slot >= 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(child_slot), SERVER_DEAD,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *) NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (remaining_children_to_start
f4c310fd2555c6faca1f980f00b161eadb089023gstein && child_slot < ap_daemons_limit) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we're still doing a 1-for-1 replacement of dead
f4c310fd2555c6faca1f980f00b161eadb089023gstein * children with new children
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein make_child(ap_server_conf, child_slot);
f4c310fd2555c6faca1f980f00b161eadb089023gstein --remaining_children_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAS_OTHER_CHILD
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (apr_proc_other_child_read(&pid, status) == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* handled */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Great, we've probably just lost a slot in the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * scoreboard. Somehow we don't know about this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * child.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING,
f4c310fd2555c6faca1f980f00b161eadb089023gstein 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "long lost child came home! (pid %ld)", (long)pid.pid);
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein }
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein /* Don't perform idle maintenance when a child dies,
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein * only do it when there's a timeout. Remember only a
f4c310fd2555c6faca1f980f00b161eadb089023gstein * finite number of children can die, and it's pretty
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pathological for a lot to die suddenly.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (remaining_children_to_start) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we hit a 1 second timeout in which none of the previous
f4c310fd2555c6faca1f980f00b161eadb089023gstein * generation of children needed to be reaped... so assume
f4c310fd2555c6faca1f980f00b161eadb089023gstein * they're all done, and pick up the slack if any is left.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein startup_children(remaining_children_to_start);
f4c310fd2555c6faca1f980f00b161eadb089023gstein remaining_children_to_start = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* In any event we really shouldn't do the code below because
f4c310fd2555c6faca1f980f00b161eadb089023gstein * few of the servers we just started are in the IDLE state
f4c310fd2555c6faca1f980f00b161eadb089023gstein * yet, so we'd mistakenly create an extra server.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein perform_idle_server_maintenance(pconf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef TPF
f4c310fd2555c6faca1f980f00b161eadb089023gstein shutdown_pending = os_check_server(tpf_server_name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_check_signals();
f4c310fd2555c6faca1f980f00b161eadb089023gstein sleep(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /*TPF */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (shutdown_pending) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Time to gracefully shut down:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Kill child processes, tell them to call child_exit, etc...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (unixd_killpg(getpgrp(), SIGTERM) < 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_reclaim_child_processes(1); /* Start with SIGTERM */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* cleanup pid file on normal shutdown */
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *pidfile = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein pidfile = ap_server_root_relative (pconf, ap_pid_fname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ( pidfile != NULL && unlink(pidfile) == 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO,
f4c310fd2555c6faca1f980f00b161eadb089023gstein 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "removed PID file %s (pid=%ld)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein pidfile, (long)getpid());
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "caught SIGTERM, shutting down");
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we've been told to restart */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_signal(SIGHUP, SIG_IGN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* not worth thinking about */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* advance to the next generation */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: we really need to make sure this new generation number isn't in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * use by any of the children.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++ap_my_generation;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global.running_generation = ap_my_generation;
f4c310fd2555c6faca1f980f00b161eadb089023gstein update_scoreboard_global();
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (index = 0; index < ap_daemons_limit; ++index) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->parent[index].process_status = SB_IDLE_DIE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Graceful restart requested, doing restart");
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* kill off the idle ones */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_mpm_pod_killpg(pod, ap_daemons_limit);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifndef SCOREBOARD_FILE
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This is mostly for debugging... so that we know what is still
f4c310fd2555c6faca1f980f00b161eadb089023gstein * gracefully dealing with existing request. But we can't really
f4c310fd2555c6faca1f980f00b161eadb089023gstein * do it if we're in a SCOREBOARD_FILE because it'll cause
f4c310fd2555c6faca1f980f00b161eadb089023gstein * corruption too easily.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sync_scoreboard_image();
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (index = 0; index < ap_daemons_limit; ++index) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->servers[index][0].status = SERVER_GRACEFUL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Kill 'em off */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (unixd_killpg(getpgrp(), SIGHUP) < 0) {
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGHUP");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_reclaim_child_processes(0); /* Not when just starting up */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "SIGHUP received. Attempting to restart");
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein }
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein static int restart_num = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int no_detach = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein no_detach = !!ap_exists_config_define("NO_DETACH");
f4c310fd2555c6faca1f980f00b161eadb089023gstein one_process = !!ap_exists_config_define("ONE_PROCESS");
f4c310fd2555c6faca1f980f00b161eadb089023gstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein /* sigh, want this only the second time around */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein if (restart_num++ == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein is_graceful = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!one_process && !no_detach) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_proc_detach();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_my_pid = getpid();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein unixd_pre_config(ptemp);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_pre_config();
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_to_start = DEFAULT_START_DAEMON;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_min_free = DEFAULT_MIN_FREE_DAEMON;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_max_free = DEFAULT_MAX_FREE_DAEMON;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_limit = HARD_SERVER_LIMIT;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pid_fname = DEFAULT_PIDLOG;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_fname = DEFAULT_SCOREBOARD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_lock_fname = DEFAULT_LOCKFILE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_extended_status = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void prefork_hooks(apr_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef AUX3
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) set42sig();
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_hook_pre_config(prefork_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (cmd->server->is_virtual) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return "PidFile directive not allowed in <VirtualHost>";
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pid_fname = arg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_fname = arg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_lock_fname = arg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_to_start = atoi(arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_min_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_min_free = atoi(arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_daemons_min_free <= 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "WARNING: detected MinSpareServers set to non-positive.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Resetting to 1 to avoid almost certain Apache failure.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Please read the documentation.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_min_free = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_max_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein if (err != NULL) {
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein return err;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein }
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_daemons_max_free = atoi(arg);
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein return NULL;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein}
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_daemons_limit = atoi(arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_daemons_limit > HARD_SERVER_LIMIT) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein "WARNING: MaxClients of %d exceeds compile time limit "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "of %d servers,", ap_daemons_limit, HARD_SERVER_LIMIT);
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein " lowering MaxClients to %d. To increase, please "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "see the", HARD_SERVER_LIMIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein " HARD_SERVER_LIMIT define in %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein AP_MPM_HARD_LIMITS_FILE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_limit = HARD_SERVER_LIMIT;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (ap_daemons_limit < 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "WARNING: Require MaxClients > 0, setting to 1");
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein ap_daemons_limit = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein return NULL;
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein}
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_max_requests(cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_requests_per_child = atoi(arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_coredumpdir (cmd_parms *cmd, void *dummy, const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_finfo_t finfo;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *fname;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein fname = ap_server_root_relative(cmd->pool, arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (finfo.filetype != APR_DIR)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm " does not exist or is not a directory", NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir));
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const command_rec prefork_cmds[] = {
f4c310fd2555c6faca1f980f00b161eadb089023gsteinUNIX_DAEMON_COMMANDS
f4c310fd2555c6faca1f980f00b161eadb089023gsteinLISTEN_COMMANDS
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "A file for logging the server process ID"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "A file for Apache to maintain runtime process management information"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The lockfile used when Apache needs to lock the accept() call"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Number of child processes launched at server startup"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("MinSpareServers", set_min_free_servers, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Minimum number of idle children, to handle request spikes"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Maximum number of idle children"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("MaxClients", set_server_limit, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Maximum number of children alive at the same time"),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Maximum number of requests a particular child serves before dying."),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The location of the directory Apache changes to before dumping core"),
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein{ NULL }
f4c310fd2555c6faca1f980f00b161eadb089023gstein};
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinmodule AP_MODULE_DECLARE_DATA mpm_prefork_module = {
f4c310fd2555c6faca1f980f00b161eadb089023gstein MPM20_MODULE_STUFF,
f4c310fd2555c6faca1f980f00b161eadb089023gstein NULL, /* hook to run before apache parses args */
f4c310fd2555c6faca1f980f00b161eadb089023gstein NULL, /* create per-directory config structure */
f4c310fd2555c6faca1f980f00b161eadb089023gstein NULL, /* merge per-directory config structures */
f4c310fd2555c6faca1f980f00b161eadb089023gstein NULL, /* create per-server config structure */
f4c310fd2555c6faca1f980f00b161eadb089023gstein NULL, /* merge per-server config structures */
f4c310fd2555c6faca1f980f00b161eadb089023gstein prefork_cmds, /* command apr_table_t */
f4c310fd2555c6faca1f980f00b161eadb089023gstein prefork_hooks, /* register hooks */
f4c310fd2555c6faca1f980f00b161eadb089023gstein};
f4c310fd2555c6faca1f980f00b161eadb089023gstein