prefork.c revision 193a91b3e014f7f85afde10ec4c0f8241f5be904
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq/* Licensed to the Apache Software Foundation (ASF) under one or more
78cd48acd325773619d78ac0d7263a99a8922faend * contributor license agreements. See the NOTICE file distributed with
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * this work for additional information regarding copyright ownership.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * The ASF licenses this file to You under the Apache License, Version 2.0
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * (the "License"); you may not use this file except in compliance with
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * the License. You may obtain a copy of the License at
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
7708bd70088b64148d7d78fd84ede43ced63c713minfrin#include "apr.h"
7708bd70088b64148d7d78fd84ede43ced63c713minfrin#include "apr_portable.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_strings.h"
36a72c96fc2dda27eadbae8a108fa428cc1419c1wrowe#include "apr_thread_proc.h"
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm#include "apr_signal.h"
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#define APR_WANT_STDIO
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#define APR_WANT_STRFUNC
70535d6421eb979ac79d8f49d31cd94d75dd8b2fjorton#include "apr_want.h"
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#if APR_HAVE_UNISTD_H
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#include <unistd.h>
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#endif
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm#if APR_HAVE_SYS_TYPES_H
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick#include <sys/types.h>
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick#endif
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick
6335eb31f0f0ed54628a04ed32946360b8b77684minfrin#define CORE_PRIVATE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "ap_config.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "httpd.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "mpm_default.h"
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#include "http_main.h"
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#include "http_log.h"
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#include "http_config.h"
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#include "http_core.h" /* for get_remote_host */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_connection.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "scoreboard.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "ap_mpm.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "unixd.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "mpm_common.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "ap_listen.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "ap_mmn.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_poll.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#ifdef HAVE_BSTRING_H
a812b025d139f465a31c76fc02ed162ed5271b03nd#include <bstring.h> /* for IRIX, FD_SET calls bzero() */
a812b025d139f465a31c76fc02ed162ed5271b03nd#endif
a812b025d139f465a31c76fc02ed162ed5271b03nd#ifdef HAVE_TIME_H
a812b025d139f465a31c76fc02ed162ed5271b03nd#include <time.h>
a812b025d139f465a31c76fc02ed162ed5271b03nd#endif
a812b025d139f465a31c76fc02ed162ed5271b03nd#ifdef HAVE_SYS_PROCESSOR_H
a812b025d139f465a31c76fc02ed162ed5271b03nd#include <sys/processor.h> /* for bindprocessor() */
a812b025d139f465a31c76fc02ed162ed5271b03nd#endif
a812b025d139f465a31c76fc02ed162ed5271b03nd
a812b025d139f465a31c76fc02ed162ed5271b03nd#include <signal.h>
a812b025d139f465a31c76fc02ed162ed5271b03nd#include <sys/times.h>
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
a812b025d139f465a31c76fc02ed162ed5271b03nd/* Limit on the total --- clients will be locked out if more servers than
00211b036b78699ace57a6d800a52e6c2d57652fnd * this are needed. It is intended solely to keep the server from crashing
00211b036b78699ace57a6d800a52e6c2d57652fnd * when things get out of hand.
00211b036b78699ace57a6d800a52e6c2d57652fnd *
a812b025d139f465a31c76fc02ed162ed5271b03nd * We keep a hard maximum number of servers, for two reasons --- first off,
a812b025d139f465a31c76fc02ed162ed5271b03nd * in case something goes seriously wrong, we want to stop the fork bomb
a812b025d139f465a31c76fc02ed162ed5271b03nd * short of actually crashing the machine we're running on by filling some
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * kernel table. Secondly, it keeps the size of the scoreboard file small
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * enough that we can read the whole thing without worrying too much about
a812b025d139f465a31c76fc02ed162ed5271b03nd * the overhead.
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe */
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#ifndef DEFAULT_SERVER_LIMIT
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#define DEFAULT_SERVER_LIMIT 256
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#endif
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe/* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * some sort of compile-time limit to help catch typos.
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe */
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#ifndef MAX_SERVER_LIMIT
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#define MAX_SERVER_LIMIT 200000
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe#endif
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe#ifndef HARD_THREAD_LIMIT
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe#define HARD_THREAD_LIMIT 1
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe#endif
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe/* config globals */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wroweint ap_threads_per_child=0; /* Worker threads per child */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic apr_proc_mutex_t *accept_mutex;
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowestatic int ap_daemons_to_start=0;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int ap_daemons_min_free=0;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int ap_daemons_max_free=0;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int ap_daemons_limit=0; /* MaxClients */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int server_limit = 0;
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowestatic int first_server_limit = 0;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int mpm_state = AP_MPMQ_STARTING;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic ap_pod_t *pod;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe/*
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * The max child slot ever assigned, preserved across restarts. Necessary
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * to deal with MaxClients changes across AP_SIG_GRACEFUL restarts. We
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * use this value to optimize routines that have to scan the entire scoreboard.
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe */
38fd849bd99e2765ee633b6dc576b5f17acdc455wroweint ap_max_daemons_limit = -1;
38fd849bd99e2765ee633b6dc576b5f17acdc455wroweserver_rec *ap_server_conf;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe/* one_process --- debugging mode variable; can be set from the command line
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * with the -X flag. If set, this gets you the child_main loop running
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * in the process which originally started up (no detach, no make_child),
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * which is a pretty nice debugging environment. (You'll get a SIGHUP
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * early in standalone_main; just continue through. This is the server
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * trying to kill off any child processes which it might have lying
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * around --- Apache doesn't keep track of their pids, it just sends
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * SIGHUP to the process group, ignoring it in the root process.
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * Continue through and you'll be fine.).
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int one_process = 0;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowestatic apr_pool_t *pconf; /* Pool for config stuff */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic apr_pool_t *pchild; /* Pool for httpd child stuff */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
9621e4c4056383e4a2b844b14687bae500b33a82wrowestatic pid_t ap_my_pid; /* it seems silly to call getpid all the time */
9621e4c4056383e4a2b844b14687bae500b33a82wrowestatic pid_t parent_pid;
9621e4c4056383e4a2b844b14687bae500b33a82wrowe#ifndef MULTITHREAD
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowestatic int my_child_num;
9621e4c4056383e4a2b844b14687bae500b33a82wrowe#endif
9621e4c4056383e4a2b844b14687bae500b33a82wroweap_generation_t volatile ap_my_generation=0;
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe
4c67ef499845a08771e81254ce6eb2324a160bc7wrowe#ifdef TPF
4c67ef499845a08771e81254ce6eb2324a160bc7wroweint tpf_child = 0;
4c67ef499845a08771e81254ce6eb2324a160bc7wrowechar tpf_server_name[INETD_SERVNAME_LENGTH+1];
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#endif /* TPF */
4c67ef499845a08771e81254ce6eb2324a160bc7wrowe
4c67ef499845a08771e81254ce6eb2324a160bc7wrowestatic volatile int die_now = 0;
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#ifdef GPROF
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe/*
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * change directory for gprof to plop the gmon.out file
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * configure in httpd.conf:
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * GprofDir $RuntimeDir/ -> $ServerRoot/$RuntimeDir/gmon.out
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * GprofDir $RuntimeDir/% -> $ServerRoot/$RuntimeDir/gprof.$pid/gmon.out
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe */
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowestatic void chdir_for_gprof(void)
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe{
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe core_server_config *sconf =
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe ap_get_module_config(ap_server_conf->module_config, &core_module);
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe char *dir = sconf->gprof_dir;
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe const char *use_dir;
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe if(dir) {
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe apr_status_t res;
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe char *buf = NULL ;
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe int len = strlen(sconf->gprof_dir) - 1;
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe if(*(dir + len) == '%') {
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe dir[len] = '\0';
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe buf = ap_append_pid(pconf, dir, "gprof.");
41c38e78e8e5dc73544571cc2b749d40869e84fawrowe }
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe use_dir = ap_server_root_relative(pconf, buf ? buf : dir);
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe res = apr_dir_make(use_dir,
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe APR_UREAD | APR_UWRITE | APR_UEXECUTE |
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe APR_GREAD | APR_GEXECUTE |
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe APR_WREAD | APR_WEXECUTE, pconf);
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
4415d997ac73262e513c0a571bd5be4f609040bawrowe ap_log_error(APLOG_MARK, APLOG_ERR, res, ap_server_conf,
4415d997ac73262e513c0a571bd5be4f609040bawrowe "gprof: error creating directory %s", dir);
4415d997ac73262e513c0a571bd5be4f609040bawrowe }
4415d997ac73262e513c0a571bd5be4f609040bawrowe }
4415d997ac73262e513c0a571bd5be4f609040bawrowe else {
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe use_dir = ap_server_root_relative(pconf, DEFAULT_REL_RUNTIMEDIR);
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe }
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe
4415d997ac73262e513c0a571bd5be4f609040bawrowe chdir(use_dir);
4415d997ac73262e513c0a571bd5be4f609040bawrowe}
4415d997ac73262e513c0a571bd5be4f609040bawrowe#else
4415d997ac73262e513c0a571bd5be4f609040bawrowe#define chdir_for_gprof()
4415d997ac73262e513c0a571bd5be4f609040bawrowe#endif
4415d997ac73262e513c0a571bd5be4f609040bawrowe
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe/* XXX - I don't know if TPF will ever use this module or not, so leave
4415d997ac73262e513c0a571bd5be4f609040bawrowe * the ap_check_signals calls in but disable them - manoj */
4415d997ac73262e513c0a571bd5be4f609040bawrowe#define ap_check_signals()
4415d997ac73262e513c0a571bd5be4f609040bawrowe
4415d997ac73262e513c0a571bd5be4f609040bawrowe/* a clean exit from a child with proper cleanup */
4415d997ac73262e513c0a571bd5be4f609040bawrowestatic void clean_child_exit(int code) __attribute__ ((noreturn));
4415d997ac73262e513c0a571bd5be4f609040bawrowestatic void clean_child_exit(int code)
4415d997ac73262e513c0a571bd5be4f609040bawrowe{
4415d997ac73262e513c0a571bd5be4f609040bawrowe mpm_state = AP_MPMQ_STOPPING;
4415d997ac73262e513c0a571bd5be4f609040bawrowe
4415d997ac73262e513c0a571bd5be4f609040bawrowe if (pchild) {
4415d997ac73262e513c0a571bd5be4f609040bawrowe apr_pool_destroy(pchild);
4415d997ac73262e513c0a571bd5be4f609040bawrowe }
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe ap_mpm_pod_close(pod);
4415d997ac73262e513c0a571bd5be4f609040bawrowe chdir_for_gprof();
4415d997ac73262e513c0a571bd5be4f609040bawrowe exit(code);
4415d997ac73262e513c0a571bd5be4f609040bawrowe}
4415d997ac73262e513c0a571bd5be4f609040bawrowe
4415d997ac73262e513c0a571bd5be4f609040bawrowestatic void accept_mutex_on(void)
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe{
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe apr_status_t rv = apr_proc_mutex_lock(accept_mutex);
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe if (rv != APR_SUCCESS) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *msg = "couldn't grab the accept mutex";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_my_generation !=
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_scoreboard_image->global->running_generation) {
00211b036b78699ace57a6d800a52e6c2d57652fnd ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, NULL, "%s", msg);
a812b025d139f465a31c76fc02ed162ed5271b03nd clean_child_exit(0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
00211b036b78699ace57a6d800a52e6c2d57652fnd else {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "%s", msg);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard exit(APEXIT_CHILDFATAL);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard}
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic void accept_mutex_off(void)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard{
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard apr_status_t rv = apr_proc_mutex_unlock(accept_mutex);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (rv != APR_SUCCESS) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard const char *msg = "couldn't release the accept mutex";
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (ap_my_generation !=
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_scoreboard_image->global->running_generation) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, NULL, "%s", msg);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* don't exit here... we have a connection to
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * process, after which point we'll see that the
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * generation changed and we'll exit cleanly
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq */
a812b025d139f465a31c76fc02ed162ed5271b03nd }
a812b025d139f465a31c76fc02ed162ed5271b03nd else {
a812b025d139f465a31c76fc02ed162ed5271b03nd ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "%s", msg);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq exit(APEXIT_CHILDFATAL);
a812b025d139f465a31c76fc02ed162ed5271b03nd }
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq }
a812b025d139f465a31c76fc02ed162ed5271b03nd}
a812b025d139f465a31c76fc02ed162ed5271b03nd
a812b025d139f465a31c76fc02ed162ed5271b03nd/* On some architectures it's safe to do unserialized accept()s in the single
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * Listen case. But it's never safe to do it in the case where there's
a812b025d139f465a31c76fc02ed162ed5271b03nd * multiple Listen statements. Define SINGLE_LISTEN_UNSERIALIZED_ACCEPT
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * when it's safe in the single Listen case.
a812b025d139f465a31c76fc02ed162ed5271b03nd */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next) {stmt;}} while(0)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#else
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard#define SAFE_ACCEPT(stmt) do {stmt;} while(0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
00211b036b78699ace57a6d800a52e6c2d57652fndAP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
00211b036b78699ace57a6d800a52e6c2d57652fnd{
00211b036b78699ace57a6d800a52e6c2d57652fnd switch(query_code){
00211b036b78699ace57a6d800a52e6c2d57652fnd case AP_MPMQ_MAX_DAEMON_USED:
00211b036b78699ace57a6d800a52e6c2d57652fnd *result = ap_daemons_limit;
00211b036b78699ace57a6d800a52e6c2d57652fnd return APR_SUCCESS;
00211b036b78699ace57a6d800a52e6c2d57652fnd case AP_MPMQ_IS_THREADED:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = AP_MPMQ_NOT_SUPPORTED;
50b2d068ddf98cf75622a0020cd143d379d1b235jfclere return APR_SUCCESS;
50b2d068ddf98cf75622a0020cd143d379d1b235jfclere case AP_MPMQ_IS_FORKED:
50b2d068ddf98cf75622a0020cd143d379d1b235jfclere *result = AP_MPMQ_DYNAMIC;
50b2d068ddf98cf75622a0020cd143d379d1b235jfclere return APR_SUCCESS;
50b2d068ddf98cf75622a0020cd143d379d1b235jfclere case AP_MPMQ_HARD_LIMIT_DAEMONS:
50b2d068ddf98cf75622a0020cd143d379d1b235jfclere *result = server_limit;
50b2d068ddf98cf75622a0020cd143d379d1b235jfclere return APR_SUCCESS;
00211b036b78699ace57a6d800a52e6c2d57652fnd case AP_MPMQ_HARD_LIMIT_THREADS:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = HARD_THREAD_LIMIT;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MAX_THREADS:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MIN_SPARE_DAEMONS:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = ap_daemons_min_free;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MIN_SPARE_THREADS:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MAX_SPARE_DAEMONS:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = ap_daemons_max_free;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MAX_SPARE_THREADS:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MAX_REQUESTS_DAEMON:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = ap_max_requests_per_child;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MAX_DAEMONS:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = server_limit;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case AP_MPMQ_MPM_STATE:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *result = mpm_state;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq return APR_SUCCESS;
a812b025d139f465a31c76fc02ed162ed5271b03nd }
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq return APR_ENOTIMPL;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq}
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq/*****************************************************************
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Connection structures and accounting...
16d38ac65d7e54cd44eeda7b23f84ee68b35094ewrowe */
16d38ac65d7e54cd44eeda7b23f84ee68b35094ewrowe
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void just_die(int sig)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard{
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard clean_child_exit(0);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard}
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic void stop_listening(int sig)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard{
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_close_listeners();
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* For a graceful stop, we want the child to exit when done */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard die_now = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* volatile just in case */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int volatile shutdown_pending;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int volatile restart_pending;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int volatile is_graceful;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic void sig_term(int sig)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard{
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (shutdown_pending == 1) {
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* Um, is this _probably_ not an error, if the user has
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * tried to do a shutdown twice quickly, so we won't
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * worry about reporting it.
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq return;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq }
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq shutdown_pending = 1;
a812b025d139f465a31c76fc02ed162ed5271b03nd is_graceful = (sig == AP_SIG_GRACEFUL_STOP);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq}
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq/* restart() is the signal handler for SIGHUP and AP_SIG_GRACEFUL
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * in the parent process, unless running in ONE_PROCESS mode
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniqstatic void restart(int sig)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (restart_pending == 1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Probably not an error - don't bother reporting it */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding restart_pending = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding is_graceful = (sig == AP_SIG_GRACEFUL);
134330b92fbc39045b7e56654f4c252fb7c53803nd}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void set_signals(void)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifndef NO_USE_SIGACTION
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct sigaction sa;
134330b92fbc39045b7e56654f4c252fb7c53803nd#endif
a812b025d139f465a31c76fc02ed162ed5271b03nd
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!one_process) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_fatal_signal_setup(ap_server_conf, pconf);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard#ifndef NO_USE_SIGACTION
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sigemptyset(&sa.sa_mask);
a812b025d139f465a31c76fc02ed162ed5271b03nd sa.sa_flags = 0;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sa.sa_handler = sig_term;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (sigaction(SIGTERM, &sa, NULL) < 0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef AP_SIG_GRACEFUL_STOP
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (sigaction(AP_SIG_GRACEFUL_STOP, &sa, NULL) < 0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "sigaction(" AP_SIG_GRACEFUL_STOP_STRING ")");
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard#endif
11c3b5180e1de6776035320b012a28bb146e7b46chuck#ifdef SIGINT
a812b025d139f465a31c76fc02ed162ed5271b03nd if (sigaction(SIGINT, &sa, NULL) < 0)
22d348febc3c258df246ac93e37945398dbf0348ianh ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
22d348febc3c258df246ac93e37945398dbf0348ianh#endif
22d348febc3c258df246ac93e37945398dbf0348ianh#ifdef SIGXCPU
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm sa.sa_handler = SIG_DFL;
a812b025d139f465a31c76fc02ed162ed5271b03nd if (sigaction(SIGXCPU, &sa, NULL) < 0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
1d7f1b96b49dafbd6cb414fb709cb85de2686a72chuck#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef SIGXFSZ
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard sa.sa_handler = SIG_DFL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (sigaction(SIGXFSZ, &sa, NULL) < 0)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef SIGPIPE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sa.sa_handler = SIG_IGN;
9b3001f2097437c3c605d29e353fda5131b9952bminfrin if (sigaction(SIGPIPE, &sa, NULL) < 0)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * processing one
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe sigaddset(&sa.sa_mask, SIGHUP);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe sigaddset(&sa.sa_mask, AP_SIG_GRACEFUL);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard sa.sa_handler = restart;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (sigaction(SIGHUP, &sa, NULL) < 0)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (sigaction(AP_SIG_GRACEFUL, &sa, NULL) < 0)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#else
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (!one_process) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#ifdef SIGXCPU
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe apr_signal(SIGXCPU, SIG_DFL);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGXCPU */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#ifdef SIGXFSZ
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe apr_signal(SIGXFSZ, SIG_DFL);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGXFSZ */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe apr_signal(SIGTERM, sig_term);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#ifdef SIGHUP
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe apr_signal(SIGHUP, restart);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGHUP */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#ifdef AP_SIG_GRACEFUL
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe apr_signal(AP_SIG_GRACEFUL, restart);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* AP_SIG_GRACEFUL */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#ifdef AP_SIG_GRACEFUL_STOP
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe apr_signal(AP_SIG_GRACEFUL_STOP, sig_term);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* AP_SIG_GRACEFUL */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#ifdef SIGPIPE
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe apr_signal(SIGPIPE, SIG_IGN);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGPIPE */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe}
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe/*****************************************************************
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * Child process main loop.
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * The following vars are static to avoid getting clobbered by longjmp();
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * they are really private to child_main.
8632261c895a84c88ae6ade6ea4c62b27bd22b3ebrianp */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic int requests_this_child;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic int num_listensocks = 0;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwroweint ap_graceful_stop_signalled(void)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe{
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* not ever called anymore... */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe return 0;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe}
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
33cb45dc8c5106018b7c2f6ae42478b109423e0eniqstatic void child_main(int child_num_arg)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_pool_t *ptrans;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_allocator_t *allocator;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_status_t status;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int i;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_listen_rec *lr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_pollset_t *pollset;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_sb_handle_t *sbh;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_alloc_t *bucket_alloc;
68ce856106f153813339db8670f6cd0ab8dea484minfrin int last_poll_idx = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
45dac0729754e413ff7c673481b219e9ab1a11f1bnicholes mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * child initializes
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq my_child_num = child_num_arg;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_my_pid = getpid();
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq requests_this_child = 0;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_fatal_signal_child_setup(ap_server_conf);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* Get a sub context for global allocations in this child, so that
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * we can have cleanups occur when the child exits.
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_allocator_create(&allocator);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_allocator_max_free_set(allocator, ap_max_mem_free);
68ce856106f153813339db8670f6cd0ab8dea484minfrin apr_pool_create_ex(&pchild, pconf, NULL, allocator);
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin apr_allocator_owner_set(allocator, pchild);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard apr_pool_tag(pchild, "pchild");
68ce856106f153813339db8670f6cd0ab8dea484minfrin
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_pool_create(&ptrans, pchild);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_pool_tag(ptrans, "transaction");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* needs to be done before we switch UIDs so we have permissions */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_reopen_scoreboard(pchild, NULL, 0);
11c3b5180e1de6776035320b012a28bb146e7b46chuck status = apr_proc_mutex_child_init(&accept_mutex, ap_lock_fname, pchild);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (status != APR_SUCCESS) {
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf,
11c3b5180e1de6776035320b012a28bb146e7b46chuck "Couldn't initialize cross-process lock in child "
11c3b5180e1de6776035320b012a28bb146e7b46chuck "(%s) (%d)", ap_lock_fname, ap_accept_lock_mech);
11c3b5180e1de6776035320b012a28bb146e7b46chuck clean_child_exit(APEXIT_CHILDFATAL);
11c3b5180e1de6776035320b012a28bb146e7b46chuck }
11c3b5180e1de6776035320b012a28bb146e7b46chuck
11c3b5180e1de6776035320b012a28bb146e7b46chuck if (unixd_setup_child()) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding clean_child_exit(APEXIT_CHILDFATAL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_run_child_init(pchild, ap_server_conf);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_create_sb_handle(&sbh, pchild, my_child_num, 0);
d7387fcd4969206172e3a2a8bbcd25a3d7011ac5rbb
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Set up the pollfd array */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* ### check the status */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) apr_pollset_create(&pollset, num_listensocks, pchild, 0);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (lr = ap_listeners, i = num_listensocks; i--; lr = lr->next) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_pollfd_t pfd = { 0 };
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pfd.desc_type = APR_POLL_SOCKET;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pfd.desc.s = lr->sd;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pfd.reqevents = APR_POLLIN;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard pfd.client_data = lr;
b999f6ba2a266bf9a92687f31bb7e76021ac5891ianh
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* ### check the status */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard (void) apr_pollset_add(pollset, &pfd);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1cde33c7e2019830f8fb3224e01649305583916etrawick mpm_state = AP_MPMQ_RUNNING;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard bucket_alloc = apr_bucket_alloc_create(pchild);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* die_now is set when AP_SIG_GRACEFUL is received in the child;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * shutdown_pending is set when SIGTERM is received when running
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * in single process mode. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (!die_now && !shutdown_pending) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding conn_rec *current_conn;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding void *csd;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * (Re)initialize this child to a pre-connection state.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb apr_pool_clear(ptrans);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
5babe00918c88eda487771fa6d6d4a1a19c0ced0chuck if ((ap_max_requests_per_child > 0
5babe00918c88eda487771fa6d6d4a1a19c0ced0chuck && requests_this_child++ >= ap_max_requests_per_child)) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm clean_child_exit(0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
35c9e4d2c0a6465746a98958ef756114834461e6minfrin
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /*
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe * Wait for an acceptable connection to arrive.
d75bc22ab2702fa770f6935f07107efff16a76f0wrowe */
11c3b5180e1de6776035320b012a28bb146e7b46chuck
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* Lock around "accept", if necessary */
45dac0729754e413ff7c673481b219e9ab1a11f1bnicholes SAFE_ACCEPT(accept_mutex_on());
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
11c3b5180e1de6776035320b012a28bb146e7b46chuck if (num_listensocks == 1) {
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* There is only one listener record, so refer to that one. */
35c9e4d2c0a6465746a98958ef756114834461e6minfrin lr = ap_listeners;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else {
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin /* multiple listening sockets - need to poll */
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin for (;;) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard apr_int32_t numdesc;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard const apr_pollfd_t *pdesc;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* timeout == -1 == wait forever */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard status = apr_pollset_poll(pollset, -1, &numdesc, &pdesc);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (status != APR_SUCCESS) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (APR_STATUS_IS_EINTR(status)) {
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin if (one_process && shutdown_pending) {
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin return;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard continue;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* Single Unix documents select as returning errnos
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * EBADF, EINTR, and EINVAL... and in none of those
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * cases does it make sense to continue. In fact
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * on Linux 2.0.x we seem to end up with EFAULT
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin * occasionally, and we'd loop forever due to it.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_ERR, status,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_server_conf, "apr_pollset_poll: (listen)");
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin SAFE_ACCEPT(accept_mutex_off());
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard clean_child_exit(1);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* We can always use pdesc[0], but sockets at position N
35c9e4d2c0a6465746a98958ef756114834461e6minfrin * could end up completely starved of attention in a very
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * busy server. Therefore, we round-robin across the
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * returned set of descriptors. While it is possible that
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the returned set of descriptors might flip around and
3d350b6e1cb11fa790a6adb428856b5dd9857fecianh * continue to starve some sockets, we happen to know the
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * internal pollset implementation retains ordering
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * stability of the sockets. Thus, the round-robin should
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ensure that a socket will eventually be serviced.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
409f0f53a83313c59f1b227ed0a340adc1081e88wrowe if (last_poll_idx >= numdesc)
409f0f53a83313c59f1b227ed0a340adc1081e88wrowe last_poll_idx = 0;
409f0f53a83313c59f1b227ed0a340adc1081e88wrowe
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* Grab a listener record from the client_data of the poll
409f0f53a83313c59f1b227ed0a340adc1081e88wrowe * descriptor, and advance our saved index to round-robin
5babe00918c88eda487771fa6d6d4a1a19c0ced0chuck * the next fetch.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ### hmm... this descriptor might have POLLERR rather
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * ### than POLLIN
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard lr = pdesc[last_poll_idx++].client_data;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding goto got_fd;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm got_fd:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* if we accept() something we don't want to die, so we have to
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * defer the exit
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding status = lr->accept_func(&csd, lr, ptrans);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (status == APR_EGENERAL) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* resource shortage or should-not-occur occured */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding clean_child_exit(1);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else if (status != APR_SUCCESS) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
1cde33c7e2019830f8fb3224e01649305583916etrawick
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /*
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * We now have a connection, so set it up with the appropriate
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * socket options, file descriptors, and read/write buffers.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
002bcf949b064d7c042465d1095cafcfc6c9b701wrowe
d75bc22ab2702fa770f6935f07107efff16a76f0wrowe current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_child_num, sbh, bucket_alloc);
002bcf949b064d7c042465d1095cafcfc6c9b701wrowe if (current_conn) {
002bcf949b064d7c042465d1095cafcfc6c9b701wrowe ap_process_connection(current_conn, csd);
d75bc22ab2702fa770f6935f07107efff16a76f0wrowe ap_lingering_close(current_conn);
002bcf949b064d7c042465d1095cafcfc6c9b701wrowe }
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin /* Check the pod and the generation number after processing a
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * connection so that we'll go away if a graceful restart occurred
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * while we were processing the connection or we are the lucky
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * idle server process that gets to die.
9379749d811388a7d0e3410940ddd6743a33d330jim */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (ap_mpm_pod_check(pod) == APR_SUCCESS) { /* selected as idle? */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard die_now = 1;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else if (ap_my_generation !=
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_scoreboard_image->global->running_generation) { /* restart? */
1cde33c7e2019830f8fb3224e01649305583916etrawick /* yeah, this could be non-graceful restart, in which case the
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * parent will kill us soon enough, but why bother checking?
446c6a9a1e1073798258f1237f8c848b5f917b66wrowe */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard die_now = 1;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe clean_child_exit(0);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard}
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int make_child(server_rec *s, int slot)
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin{
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin int pid;
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin if (slot + 1 > ap_max_daemons_limit) {
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin ap_max_daemons_limit = slot + 1;
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (one_process) {
1cde33c7e2019830f8fb3224e01649305583916etrawick apr_signal(SIGHUP, sig_term);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* Don't catch AP_SIG_GRACEFUL in ONE_PROCESS mode :) */
446c6a9a1e1073798258f1237f8c848b5f917b66wrowe apr_signal(SIGINT, sig_term);
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin#ifdef SIGQUIT
1cde33c7e2019830f8fb3224e01649305583916etrawick apr_signal(SIGQUIT, SIG_DFL);
6bdb2c094666367615890147775bb18761216c8dminfrin#endif
6bdb2c094666367615890147775bb18761216c8dminfrin apr_signal(SIGTERM, sig_term);
6bdb2c094666367615890147775bb18761216c8dminfrin child_main(slot);
6bdb2c094666367615890147775bb18761216c8dminfrin return 0;
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe }
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe
9865751743e928ea0a9ad83faa04a738001932deminfrin (void) ap_update_child_status_from_indexes(slot, 0, SERVER_STARTING,
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe (request_rec *) NULL);
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe
002bcf949b064d7c042465d1095cafcfc6c9b701wrowe
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe#ifdef _OSD_POSIX
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe /* BS2000 requires a "special" version of fork() before a setuid() call */
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe if ((pid = os_fork(unixd_config.user_name)) == -1) {
002bcf949b064d7c042465d1095cafcfc6c9b701wrowe#elif defined(TPF)
002bcf949b064d7c042465d1095cafcfc6c9b701wrowe if ((pid = os_fork(s, slot)) == -1) {
d75bc22ab2702fa770f6935f07107efff16a76f0wrowe#else
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin if ((pid = fork()) == -1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "fork: Unable to fork new process");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* fork didn't succeed. Fix the scoreboard or else
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * it will say SERVER_STARTING forever and ever
11c3b5180e1de6776035320b012a28bb146e7b46chuck */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status_from_indexes(slot, 0, SERVER_DEAD,
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe (request_rec *) NULL);
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe /* In case system resources are maxxed out, we don't want
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe * Apache running away with the CPU trying to fork over and
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe * over and over again.
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq sleep(10);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
a812b025d139f465a31c76fc02ed162ed5271b03nd return -1;
a812b025d139f465a31c76fc02ed162ed5271b03nd }
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe if (!pid) {
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe#ifdef HAVE_BINDPROCESSOR
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* by default AIX binds to a single processor
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe * this bit unbinds children which will then bind to another cpu
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int status = bindprocessor(BINDPROCESS, (int)getpid(),
af952917c05e56874069e1e5f64e6473bb478b68minfrin PROCESSOR_CLASS_ANY);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (status != OK) {
af952917c05e56874069e1e5f64e6473bb478b68minfrin ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
af952917c05e56874069e1e5f64e6473bb478b68minfrin ap_server_conf, "processor unbind failed %d", status);
af952917c05e56874069e1e5f64e6473bb478b68minfrin }
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin#endif
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin RAISE_SIGSTOP(MAKE_CHILD);
35c9e4d2c0a6465746a98958ef756114834461e6minfrin AP_MONCONTROL(1);
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* Disable the parent's signal handlers and set up proper handling in
4a7df15077ff65dbf3b2cf68fa3063273ac0a547minfrin * the child.
dcc56911d2b95e73554ff8ced9f72fd456d73881minfrin */
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim apr_signal(SIGHUP, just_die);
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim apr_signal(SIGTERM, just_die);
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* The child process just closes listeners on AP_SIG_GRACEFUL.
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * The pod is used for signalling the graceful restart.
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim */
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim apr_signal(AP_SIG_GRACEFUL, stop_listening);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding child_main(slot);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
af952917c05e56874069e1e5f64e6473bb478b68minfrin ap_scoreboard_image->parent[slot].pid = pid;
af952917c05e56874069e1e5f64e6473bb478b68minfrin
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe return 0;
af952917c05e56874069e1e5f64e6473bb478b68minfrin}
af952917c05e56874069e1e5f64e6473bb478b68minfrin
af952917c05e56874069e1e5f64e6473bb478b68minfrin
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe/* start up a bunch of children */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic void startup_children(int number_to_start)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe{
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int i;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq for (i = 0; number_to_start && i < ap_daemons_limit; ++i) {
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq if (ap_scoreboard_image->servers[i][0].status != SERVER_DEAD) {
a812b025d139f465a31c76fc02ed162ed5271b03nd continue;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq }
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq if (make_child(ap_server_conf, i) < 0) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe break;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe --number_to_start;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe}
af952917c05e56874069e1e5f64e6473bb478b68minfrin
af952917c05e56874069e1e5f64e6473bb478b68minfrin
af952917c05e56874069e1e5f64e6473bb478b68minfrin/*
af952917c05e56874069e1e5f64e6473bb478b68minfrin * idle_spawn_rate is the number of children that will be spawned on the
af952917c05e56874069e1e5f64e6473bb478b68minfrin * next maintenance cycle if there aren't enough idle servers. It is
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
35c9e4d2c0a6465746a98958ef756114834461e6minfrin * without the need to spawn.
dcc56911d2b95e73554ff8ced9f72fd456d73881minfrin */
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianhstatic int idle_spawn_rate = 1;
4224d5789080ea5586d49420da1e1996f5653bb5ianh#ifndef MAX_SPAWN_RATE
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim#define MAX_SPAWN_RATE (32)
af952917c05e56874069e1e5f64e6473bb478b68minfrin#endif
af952917c05e56874069e1e5f64e6473bb478b68minfrinstatic int hold_off_on_exponential_spawning;
af952917c05e56874069e1e5f64e6473bb478b68minfrin
af952917c05e56874069e1e5f64e6473bb478b68minfrinstatic void perform_idle_server_maintenance(apr_pool_t *p)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe{
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int i;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int to_kill;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int idle_count;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe worker_score *ws;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int free_length;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int free_slots[MAX_SPAWN_RATE];
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int last_non_dead;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int total_non_dead;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* initialize the free_list */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe free_length = 0;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe to_kill = -1;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe idle_count = 0;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe last_non_dead = -1;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe total_non_dead = 0;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe for (i = 0; i < ap_daemons_limit; ++i) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe int status;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (i >= ap_max_daemons_limit && free_length == idle_spawn_rate)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
9379749d811388a7d0e3410940ddd6743a33d330jim ws = &ap_scoreboard_image->servers[i][0];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding status = ws->status;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (status == SERVER_DEAD) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* try to keep children numbers as low as possible */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (free_length < idle_spawn_rate) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding free_slots[free_length] = i;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ++free_length;
3c59b18ce62f97468aaa5951d4e21a5478ef36ecminfrin }
9379749d811388a7d0e3410940ddd6743a33d330jim }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We consider a starting server as idle because we started it
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * at least a cycle ago, and if it still hasn't finished starting
3c59b18ce62f97468aaa5951d4e21a5478ef36ecminfrin * then we're just going to swamp things worse by forking more.
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * So we hopefully won't need to fork more if we count it.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This depends on the ordering of SERVER_READY and SERVER_STARTING.
3c59b18ce62f97468aaa5951d4e21a5478ef36ecminfrin */
9379749d811388a7d0e3410940ddd6743a33d330jim if (status <= SERVER_READY) {
9379749d811388a7d0e3410940ddd6743a33d330jim ++ idle_count;
9379749d811388a7d0e3410940ddd6743a33d330jim /* always kill the highest numbered child if we have to...
9379749d811388a7d0e3410940ddd6743a33d330jim * no really well thought out reason ... other than observing
3c59b18ce62f97468aaa5951d4e21a5478ef36ecminfrin * the server behaviour under linux where lower numbered children
3c59b18ce62f97468aaa5951d4e21a5478ef36ecminfrin * tend to service more hits (and hence are more likely to have
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * their data in cpu caches).
3c59b18ce62f97468aaa5951d4e21a5478ef36ecminfrin */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding to_kill = i;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
9379749d811388a7d0e3410940ddd6743a33d330jim
9379749d811388a7d0e3410940ddd6743a33d330jim ++total_non_dead;
9379749d811388a7d0e3410940ddd6743a33d330jim last_non_dead = i;
9379749d811388a7d0e3410940ddd6743a33d330jim }
9379749d811388a7d0e3410940ddd6743a33d330jim }
9379749d811388a7d0e3410940ddd6743a33d330jim ap_max_daemons_limit = last_non_dead + 1;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (idle_count > ap_daemons_max_free) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* kill off one child... we use the pod because that'll cause it to
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * shut down gracefully, in case it happened to pick up a request
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * while we were counting
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
9379749d811388a7d0e3410940ddd6743a33d330jim ap_mpm_pod_signal(pod);
9379749d811388a7d0e3410940ddd6743a33d330jim idle_spawn_rate = 1;
9379749d811388a7d0e3410940ddd6743a33d330jim }
9379749d811388a7d0e3410940ddd6743a33d330jim else if (idle_count < ap_daemons_min_free) {
9379749d811388a7d0e3410940ddd6743a33d330jim /* terminate the free list */
9379749d811388a7d0e3410940ddd6743a33d330jim if (free_length == 0) {
9379749d811388a7d0e3410940ddd6743a33d330jim /* only report this condition once */
9379749d811388a7d0e3410940ddd6743a33d330jim static int reported = 0;
11c3b5180e1de6776035320b012a28bb146e7b46chuck
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!reported) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
24efed0910118b762a4eb84830875d4714b8d315ianh "server reached MaxClients setting, consider"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " raising the MaxClients setting");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding reported = 1;
066877f1a045103acfdd376d48cdd473c33f409bdougm }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding idle_spawn_rate = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (idle_spawn_rate >= 8) {
9379749d811388a7d0e3410940ddd6743a33d330jim ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
9379749d811388a7d0e3410940ddd6743a33d330jim "server seems busy, (you may need "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "to increase StartServers, or Min/MaxSpareServers), "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "spawning %d children, there are %d idle, and "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "%d total children", idle_spawn_rate,
9379749d811388a7d0e3410940ddd6743a33d330jim idle_count, total_non_dead);
9379749d811388a7d0e3410940ddd6743a33d330jim }
9379749d811388a7d0e3410940ddd6743a33d330jim for (i = 0; i < free_length; ++i) {
9379749d811388a7d0e3410940ddd6743a33d330jim#ifdef TPF
9379749d811388a7d0e3410940ddd6743a33d330jim if (make_child(ap_server_conf, free_slots[i]) == -1) {
9379749d811388a7d0e3410940ddd6743a33d330jim if(free_length == 1) {
9379749d811388a7d0e3410940ddd6743a33d330jim shutdown_pending = 1;
9379749d811388a7d0e3410940ddd6743a33d330jim ap_log_error(APLOG_MARK, APLOG_EMERG, 0, ap_server_conf,
9379749d811388a7d0e3410940ddd6743a33d330jim "No active child processes: shutting down");
9379749d811388a7d0e3410940ddd6743a33d330jim }
9379749d811388a7d0e3410940ddd6743a33d330jim }
9379749d811388a7d0e3410940ddd6743a33d330jim#else
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding make_child(ap_server_conf, free_slots[i]);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe#endif /* TPF */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* the next time around we want to spawn twice as many if this
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * wasn't good enough, but not if we've just done a graceful
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (hold_off_on_exponential_spawning) {
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe --hold_off_on_exponential_spawning;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe else if (idle_spawn_rate < MAX_SPAWN_RATE) {
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe idle_spawn_rate *= 2;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe else {
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe idle_spawn_rate = 1;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe}
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe/*****************************************************************
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * Executive routines.
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe */
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wroweint ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe{
433dc2d5dae74ed067db6175010ff973d02511e9jerenkrantz int index;
433dc2d5dae74ed067db6175010ff973d02511e9jerenkrantz int remaining_children_to_start;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe apr_status_t rv;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_log_pid(pconf, ap_pid_fname);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* Initialize cross-process accept lock */
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_lock_fname = apr_psprintf(_pconf, "%s.%" APR_PID_T_FMT,
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_server_root_relative(_pconf, ap_lock_fname),
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_my_pid);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe rv = apr_proc_mutex_create(&accept_mutex, ap_lock_fname,
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_accept_lock_mech, _pconf);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe if (rv != APR_SUCCESS) {
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
75b0a6a06ca1f4de80e3dd2a09c9f0c7d0a56089wrowe "Couldn't create accept lock (%s) (%d)",
75b0a6a06ca1f4de80e3dd2a09c9f0c7d0a56089wrowe ap_lock_fname, ap_accept_lock_mech);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe mpm_state = AP_MPMQ_STOPPING;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe return 1;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe#if APR_USE_SYSVSEM_SERIALIZE
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe if (ap_accept_lock_mech == APR_LOCK_DEFAULT ||
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_accept_lock_mech == APR_LOCK_SYSVSEM) {
4415d997ac73262e513c0a571bd5be4f609040bawrowe#else
4415d997ac73262e513c0a571bd5be4f609040bawrowe if (ap_accept_lock_mech == APR_LOCK_SYSVSEM) {
4415d997ac73262e513c0a571bd5be4f609040bawrowe#endif
4415d997ac73262e513c0a571bd5be4f609040bawrowe rv = unixd_set_proc_mutex_perms(accept_mutex);
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe if (rv != APR_SUCCESS) {
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
4415d997ac73262e513c0a571bd5be4f609040bawrowe "Couldn't set permissions on cross-process lock; "
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe "check User and Group directives");
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe mpm_state = AP_MPMQ_STOPPING;
4415d997ac73262e513c0a571bd5be4f609040bawrowe return 1;
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe }
4415d997ac73262e513c0a571bd5be4f609040bawrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe if (!is_graceful) {
446c6a9a1e1073798258f1237f8c848b5f917b66wrowe if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe mpm_state = AP_MPMQ_STOPPING;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe return 1;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe /* fix the generation number in the global score; we just got a new,
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * cleared scoreboard
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe */
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe ap_scoreboard_image->global->running_generation = ap_my_generation;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe set_signals();
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe if (one_process) {
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe AP_MONCONTROL(1);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe make_child(ap_server_conf, 0);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_daemons_max_free < ap_daemons_min_free + 1) /* Don't thrash... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_daemons_max_free = ap_daemons_min_free + 1;
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* If we're doing a graceful_restart then we're going to see a lot
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * of children exiting immediately when we get into the main loop
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * below (because we just sent them AP_SIG_GRACEFUL). This happens pretty
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * rapidly... and for each one that exits we'll start a new one until
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * we reach at least daemons_min_free. But we may be permitted to
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * start more than that, so we'll just keep track of how many we're
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * supposed to start up without the 1 second penalty between each fork.
529005244758297d4415aa912c67a67f805349bcianh */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard remaining_children_to_start = ap_daemons_to_start;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (remaining_children_to_start > ap_daemons_limit) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard remaining_children_to_start = ap_daemons_limit;
529005244758297d4415aa912c67a67f805349bcianh }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (!is_graceful) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard startup_children(remaining_children_to_start);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard remaining_children_to_start = 0;
529005244758297d4415aa912c67a67f805349bcianh }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* give the system some time to recover before kicking into
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * exponential mode
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard */
529005244758297d4415aa912c67a67f805349bcianh hold_off_on_exponential_spawning = 10;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq "%s configured -- resuming normal operations",
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_get_server_description());
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq "Server built: %s", ap_get_server_built());
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq "AcceptMutex: %s (default: %s)",
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq apr_proc_mutex_name(accept_mutex),
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq apr_proc_mutex_defname());
a812b025d139f465a31c76fc02ed162ed5271b03nd#endif
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq restart_pending = shutdown_pending = 0;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
a812b025d139f465a31c76fc02ed162ed5271b03nd mpm_state = AP_MPMQ_RUNNING;
a812b025d139f465a31c76fc02ed162ed5271b03nd
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq while (!restart_pending && !shutdown_pending) {
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq int child_slot;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq apr_exit_why_e exitwhy;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq int status, processed_status;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* this is a memory leak, but I'll fix it later. */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq apr_proc_t pid;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_wait_or_timeout(&exitwhy, &status, &pid, pconf);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* XXX: if it takes longer than 1 second for all our children
a812b025d139f465a31c76fc02ed162ed5271b03nd * to start up and get into IDLE state then we may spawn an
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * extra child
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq */
a812b025d139f465a31c76fc02ed162ed5271b03nd if (pid.pid != -1) {
a812b025d139f465a31c76fc02ed162ed5271b03nd processed_status = ap_process_child_status(&pid, exitwhy, status);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq if (processed_status == APEXIT_CHILDFATAL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding mpm_state = AP_MPMQ_STOPPING;
11c3b5180e1de6776035320b012a28bb146e7b46chuck return 1;
11c3b5180e1de6776035320b012a28bb146e7b46chuck }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* non-fatal death... note that it's gone in the scoreboard. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding child_slot = find_child_by_pid(&pid);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (child_slot >= 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status_from_indexes(child_slot, 0, SERVER_DEAD,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (request_rec *) NULL);
a6314dfa8dd8a0d69db16288581e4950a2dd3955minfrin if (processed_status == APEXIT_CHILDSICK) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* child detected a resource shortage (E[NM]FILE, ENOBUFS, etc)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * cut the fork rate to the minimum
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding idle_spawn_rate = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else if (remaining_children_to_start
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard && child_slot < ap_daemons_limit) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* we're still doing a 1-for-1 replacement of dead
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * children with new children
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding make_child(ap_server_conf, child_slot);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard --remaining_children_to_start;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard#if APR_HAS_OTHER_CHILD
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else if (apr_proc_other_child_alert(&pid, APR_OC_REASON_DEATH, status) == APR_SUCCESS) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* handled */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard#endif
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (is_graceful) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Great, we've probably just lost a slot in the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * scoreboard. Somehow we don't know about this
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * child.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding 0, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "long lost child came home! (pid %ld)", (long)pid.pid);
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Don't perform idle maintenance when a child dies,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * only do it when there's a timeout. Remember only a
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * finite number of children can die, and it's pretty
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * pathological for a lot to die suddenly.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe }
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else if (remaining_children_to_start) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* we hit a 1 second timeout in which none of the previous
066877f1a045103acfdd376d48cdd473c33f409bdougm * generation of children needed to be reaped... so assume
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * they're all done, and pick up the slack if any is left.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding startup_children(remaining_children_to_start);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding remaining_children_to_start = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* In any event we really shouldn't do the code below because
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * few of the servers we just started are in the IDLE state
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * yet, so we'd mistakenly create an extra server.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
11c3b5180e1de6776035320b012a28bb146e7b46chuck continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding perform_idle_server_maintenance(pconf);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef TPF
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding shutdown_pending = os_check_server(tpf_server_name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_check_signals();
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sleep(1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif /*TPF */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } /* one_process */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard mpm_state = AP_MPMQ_STOPPING;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (shutdown_pending && !is_graceful) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Time to shut down:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Kill child processes, tell them to call child_exit, etc...
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard */
11c3b5180e1de6776035320b012a28bb146e7b46chuck if (unixd_killpg(getpgrp(), SIGTERM) < 0) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_reclaim_child_processes(1); /* Start with SIGTERM */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
1cde33c7e2019830f8fb3224e01649305583916etrawick /* cleanup pid file on normal shutdown */
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb {
1cde33c7e2019830f8fb3224e01649305583916etrawick const char *pidfile = NULL;
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb pidfile = ap_server_root_relative (pconf, ap_pid_fname);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ( pidfile != NULL && unlink(pidfile) == 0)
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_log_error(APLOG_MARK, APLOG_INFO,
11c3b5180e1de6776035320b012a28bb146e7b46chuck 0, ap_server_conf,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard "removed PID file %s (pid=%ld)",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pidfile, (long)getpid());
1cde33c7e2019830f8fb3224e01649305583916etrawick }
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard "caught SIGTERM, shutting down");
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard return 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } else if (shutdown_pending) {
1cde33c7e2019830f8fb3224e01649305583916etrawick /* Time to perform a graceful shut down:
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb * Reap the inactive children, and ask the active ones
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * to close their listeners, then wait until they are
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * all done to exit.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard int active_children;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_time_t cutoff = 0;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Stop listening */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_close_listeners();
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* kill off the idle ones */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_mpm_pod_killpg(pod, ap_max_daemons_limit);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Send SIGUSR1 to the active children */
11c3b5180e1de6776035320b012a28bb146e7b46chuck active_children = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (index = 0; index < ap_daemons_limit; ++index) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Ask each child to close its listeners. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_mpm_safe_kill(MPM_CHILD_PID(index), AP_SIG_GRACEFUL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding active_children++;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Allow each child which actually finished to exit */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_relieve_child_processes();
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* cleanup pid file */
11c3b5180e1de6776035320b012a28bb146e7b46chuck {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *pidfile = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pidfile = ap_server_root_relative (pconf, ap_pid_fname);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ( pidfile != NULL && unlink(pidfile) == 0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_INFO,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding 0, ap_server_conf,
af952917c05e56874069e1e5f64e6473bb478b68minfrin "removed PID file %s (pid=%ld)",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pidfile, (long)getpid());
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh
4a7df15077ff65dbf3b2cf68fa3063273ac0a547minfrin ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh "caught " AP_SIG_GRACEFUL_STOP_STRING ", shutting down gracefully");
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh if (ap_graceful_shutdown_timeout) {
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh cutoff = apr_time_now() +
4a7df15077ff65dbf3b2cf68fa3063273ac0a547minfrin apr_time_from_sec(ap_graceful_shutdown_timeout);
dcc56911d2b95e73554ff8ced9f72fd456d73881minfrin }
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh /* Don't really exit until each child has finished */
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh shutdown_pending = 0;
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh do {
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh /* Pause for a second */
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh sleep(1);
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh /* Relieve any children which have now exited */
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh ap_relieve_child_processes();
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh active_children = 0;
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh for (index = 0; index < ap_daemons_limit; ++index) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_mpm_safe_kill(MPM_CHILD_PID(index), 0) == APR_SUCCESS) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding active_children = 1;
11c3b5180e1de6776035320b012a28bb146e7b46chuck /* Having just one child is enough to stay around */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while (!shutdown_pending && active_children &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (!ap_graceful_shutdown_timeout || apr_time_now() < cutoff));
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We might be here because we received SIGTERM, either
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * way, try and make sure that all of our processes are
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * really dead.
af952917c05e56874069e1e5f64e6473bb478b68minfrin */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding unixd_killpg(getpgrp(), SIGTERM);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 1;
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin }
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin /* we've been told to restart */
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin apr_signal(SIGHUP, SIG_IGN);
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin apr_signal(AP_SIG_GRACEFUL, SIG_IGN);
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin if (one_process) {
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin /* not worth thinking about */
10306ac2c175f420e6989568f4c8535a5dbc1349minfrin return 1;
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin }
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin /* advance to the next generation */
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin /* XXX: we really need to make sure this new generation number isn't in
35c9e4d2c0a6465746a98958ef756114834461e6minfrin * use by any of the children.
35c9e4d2c0a6465746a98958ef756114834461e6minfrin */
35c9e4d2c0a6465746a98958ef756114834461e6minfrin ++ap_my_generation;
35c9e4d2c0a6465746a98958ef756114834461e6minfrin ap_scoreboard_image->global->running_generation = ap_my_generation;
35c9e4d2c0a6465746a98958ef756114834461e6minfrin
35c9e4d2c0a6465746a98958ef756114834461e6minfrin if (is_graceful) {
35c9e4d2c0a6465746a98958ef756114834461e6minfrin ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard "Graceful restart requested, doing restart");
35c9e4d2c0a6465746a98958ef756114834461e6minfrin
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* kill off the idle ones */
35c9e4d2c0a6465746a98958ef756114834461e6minfrin ap_mpm_pod_killpg(pod, ap_max_daemons_limit);
35c9e4d2c0a6465746a98958ef756114834461e6minfrin
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* This is mostly for debugging... so that we know what is still
35c9e4d2c0a6465746a98958ef756114834461e6minfrin * gracefully dealing with existing request. This will break
4224d5789080ea5586d49420da1e1996f5653bb5ianh * in a very nasty way if we ever have the scoreboard totally
4224d5789080ea5586d49420da1e1996f5653bb5ianh * file-based (no shared memory)
4224d5789080ea5586d49420da1e1996f5653bb5ianh */
4224d5789080ea5586d49420da1e1996f5653bb5ianh for (index = 0; index < ap_daemons_limit; ++index) {
4224d5789080ea5586d49420da1e1996f5653bb5ianh if (ap_scoreboard_image->servers[index][0].status != SERVER_DEAD) {
4224d5789080ea5586d49420da1e1996f5653bb5ianh ap_scoreboard_image->servers[index][0].status = SERVER_GRACEFUL;
4224d5789080ea5586d49420da1e1996f5653bb5ianh /* Ask each child to close its listeners.
4224d5789080ea5586d49420da1e1996f5653bb5ianh *
4224d5789080ea5586d49420da1e1996f5653bb5ianh * NOTE: we use the scoreboard, because if we send SIGUSR1
4224d5789080ea5586d49420da1e1996f5653bb5ianh * to every process in the group, this may include CGI's,
4224d5789080ea5586d49420da1e1996f5653bb5ianh * piped loggers, etc. They almost certainly won't handle
4224d5789080ea5586d49420da1e1996f5653bb5ianh * it gracefully.
fa861fc5a880d2c3a5ecc0ec71fa7da556adf5c1wrowe */
4224d5789080ea5586d49420da1e1996f5653bb5ianh ap_mpm_safe_kill(ap_scoreboard_image->parent[index].pid, AP_SIG_GRACEFUL);
4224d5789080ea5586d49420da1e1996f5653bb5ianh }
4224d5789080ea5586d49420da1e1996f5653bb5ianh }
35c9e4d2c0a6465746a98958ef756114834461e6minfrin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb /* Kill 'em off */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (unixd_killpg(getpgrp(), SIGHUP) < 0) {
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGHUP");
11c3b5180e1de6776035320b012a28bb146e7b46chuck }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_reclaim_child_processes(0); /* Not when just starting up */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "SIGHUP received. Attempting to restart");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* This really should be a post_config hook, but the error log is already
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * redirected by that point, so we need to do this in the open_logs phase.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding static int restart_num = 0;
af952917c05e56874069e1e5f64e6473bb478b68minfrin int startup = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int level_flags = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_status_t rv;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim pconf = p;
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim ap_server_conf = s;
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* the reverse of pre_config, we want this only the first time around */
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim if (restart_num++ == 0) {
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim startup = 1;
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim level_flags |= APLOG_STARTUP;
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim }
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) {
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim ap_log_error(APLOG_MARK, APLOG_ALERT | level_flags, 0,
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim (startup ? NULL : s),
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim "no listening sockets available, shutting down");
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim return DONE;
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim }
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim if ((rv = ap_mpm_pod_open(pconf, &pod))) {
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim ap_log_error(APLOG_MARK, APLOG_CRIT | level_flags, rv,
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim (startup ? NULL : s),
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim "could not open pipe-of-death");
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim return DONE;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe }
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe return OK;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe}
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowestatic int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe{
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe static int restart_num = 0;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe int no_detach, debug, foreground;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe apr_status_t rv;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe mpm_state = AP_MPMQ_STARTING;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe debug = ap_exists_config_define("DEBUG");
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe if (debug) {
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe foreground = one_process = 1;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe no_detach = 0;
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe }
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe else
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe {
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe no_detach = ap_exists_config_define("NO_DETACH");
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe one_process = ap_exists_config_define("ONE_PROCESS");
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe foreground = ap_exists_config_define("FOREGROUND");
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* sigh, want this only the second time around */
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe if (restart_num++ == 1) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe is_graceful = 0;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (!one_process && !foreground) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe : APR_PROC_DETACH_DAEMONIZE);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (rv != APR_SUCCESS) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "apr_proc_detach failed");
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe return HTTP_INTERNAL_SERVER_ERROR;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe parent_pid = ap_my_pid = getpid();
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe unixd_pre_config(ptemp);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_listen_pre_config();
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_daemons_to_start = DEFAULT_START_DAEMON;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_daemons_min_free = DEFAULT_MIN_FREE_DAEMON;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_daemons_max_free = DEFAULT_MAX_FREE_DAEMON;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe server_limit = DEFAULT_SERVER_LIMIT;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_daemons_limit = server_limit;
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_pid_fname = DEFAULT_PIDLOG;
433dc2d5dae74ed067db6175010ff973d02511e9jerenkrantz ap_lock_fname = DEFAULT_LOCKFILE;
433dc2d5dae74ed067db6175010ff973d02511e9jerenkrantz ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_extended_status = 0;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe#endif
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe return OK;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe}
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowestatic int prefork_check_config(apr_pool_t *p, apr_pool_t *plog,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe apr_pool_t *ptemp, server_rec *s)
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe{
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe static int restart_num = 0;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe int startup = 0;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* the reverse of pre_config, we want this only the first time around */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (restart_num++ == 0) {
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe startup = 1;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe
4c67ef499845a08771e81254ce6eb2324a160bc7wrowe if (server_limit > MAX_SERVER_LIMIT) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (startup) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "WARNING: ServerLimit of %d exceeds compile-time "
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe "limit of", server_limit);
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe " %d servers, decreasing to %d.",
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe MAX_SERVER_LIMIT, MAX_SERVER_LIMIT);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe } else {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe "ServerLimit of %d exceeds compile-time limit "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "of %d, decreasing to match",
4415d997ac73262e513c0a571bd5be4f609040bawrowe server_limit, MAX_SERVER_LIMIT);
4415d997ac73262e513c0a571bd5be4f609040bawrowe }
4415d997ac73262e513c0a571bd5be4f609040bawrowe server_limit = MAX_SERVER_LIMIT;
4415d997ac73262e513c0a571bd5be4f609040bawrowe }
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe else if (server_limit < 1) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (startup) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
4cc02d7521758b07c7cd240e8ea32fb7a20909cfwrowe "WARNING: ServerLimit of %d not allowed, "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "increasing to 1.", server_limit);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe } else {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "ServerLimit of %d not allowed, increasing to 1",
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe server_limit);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe server_limit = 1;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* you cannot change ServerLimit across a restart; ignore
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe * any such attempts
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (!first_server_limit) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe first_server_limit = server_limit;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe else if (server_limit != first_server_limit) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* don't need a startup console version here */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "changing ServerLimit to %d from original value of %d "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "not allowed during restart",
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe server_limit, first_server_limit);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe server_limit = first_server_limit;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe }
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (ap_daemons_limit > server_limit) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (startup) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "WARNING: MaxClients of %d exceeds ServerLimit "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "value of", ap_daemons_limit);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe " %d servers, decreasing MaxClients to %d.",
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe server_limit, server_limit);
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe " To increase, please see the ServerLimit "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "directive.");
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe } else {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "MaxClients of %d exceeds ServerLimit value "
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "of %d, decreasing to match",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_limit, server_limit);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_limit = server_limit;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe else if (ap_daemons_limit < 1) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (startup) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "WARNING: MaxClients of %d not allowed, "
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "increasing to 1.", ap_daemons_limit);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe } else {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "MaxClients of %d not allowed, increasing to 1",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_limit);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_limit = 1;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* ap_daemons_to_start > ap_daemons_limit checked in ap_mpm_run() */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (ap_daemons_to_start < 0) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (startup) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "WARNING: StartServers of %d not allowed, "
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "increasing to 1.", ap_daemons_to_start);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe } else {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "StartServers of %d not allowed, increasing to 1",
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_daemons_to_start);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_to_start = 1;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (ap_daemons_min_free < 1) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (startup) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "WARNING: MinSpareServers of %d not allowed, "
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "increasing to 1", ap_daemons_min_free);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe " to avoid almost certain server failure.");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe " Please read the documentation.");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe } else {
52489511342e4ff3fe399e57f29d38e5c4227bc8trawick ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "MinSpareServers of %d not allowed, increasing to 1",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_min_free);
52489511342e4ff3fe399e57f29d38e5c4227bc8trawick }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_min_free = 1;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* ap_daemons_max_free < ap_daemons_min_free + 1 checked in ap_mpm_run() */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6c244ee56578707b20a86e0e938498299a93b6cnd return OK;
e6c244ee56578707b20a86e0e938498299a93b6cnd}
e6c244ee56578707b20a86e0e938498299a93b6cnd
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic void prefork_hooks(apr_pool_t *p)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe{
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* Our open_logs hook function must run before the core's, or stderr
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * will be redirected to a file, and the messages won't print to the
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * console.
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe static const char *const aszSucc[] = {"core.c", NULL};
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
e6c244ee56578707b20a86e0e938498299a93b6cnd#ifdef AUX3
e6c244ee56578707b20a86e0e938498299a93b6cnd (void) set42sig();
e6c244ee56578707b20a86e0e938498299a93b6cnd#endif
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_hook_open_logs(prefork_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* we need to set the MPM state before other pre-config hooks use MPM query
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * to retrieve it, so register as REALLY_FIRST
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_hook_pre_config(prefork_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_hook_check_config(prefork_check_config, NULL, NULL, APR_HOOK_MIDDLE);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe}
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe{
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
9a806b671337b22acf6418e60a83f6bbeabdf771wrowe if (err != NULL) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe return err;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_daemons_to_start = atoi(arg);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard return NULL;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard}
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic const char *set_min_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe{
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (err != NULL) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe return err;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_daemons_min_free = atoi(arg);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe}
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic const char *set_max_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe{
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (err != NULL) {
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb return err;
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb }
9379749d811388a7d0e3410940ddd6743a33d330jim
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb ap_daemons_max_free = atoi(arg);
9379749d811388a7d0e3410940ddd6743a33d330jim return NULL;
9379749d811388a7d0e3410940ddd6743a33d330jim}
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbbstatic const char *set_max_clients (cmd_parms *cmd, void *dummy, const char *arg)
93aa7afe1af831ee8b23aa0d97323c388e3fb8d3ianh{
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq if (err != NULL) {
a812b025d139f465a31c76fc02ed162ed5271b03nd return err;
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq }
a812b025d139f465a31c76fc02ed162ed5271b03nd
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb ap_daemons_limit = atoi(arg);
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb return NULL;
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb}
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrinstatic const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin{
35c9e4d2c0a6465746a98958ef756114834461e6minfrin const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
35c9e4d2c0a6465746a98958ef756114834461e6minfrin if (err != NULL) {
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb return err;
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb }
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb server_limit = atoi(arg);
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb return NULL;
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb}
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbbstatic const command_rec prefork_cmds[] = {
4a7df15077ff65dbf3b2cf68fa3063273ac0a547minfrinUNIX_DAEMON_COMMANDS,
4ecd546edd89824908c2a9ad2e07339d89368f9cmartinLISTEN_COMMANDS,
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianhAP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF,
4ecd546edd89824908c2a9ad2e07339d89368f9cmartin "Number of child processes launched at server startup"),
4224d5789080ea5586d49420da1e1996f5653bb5ianhAP_INIT_TAKE1("MinSpareServers", set_min_free_servers, NULL, RSRC_CONF,
4224d5789080ea5586d49420da1e1996f5653bb5ianh "Minimum number of idle children, to handle request spikes"),
4224d5789080ea5586d49420da1e1996f5653bb5ianhAP_INIT_TAKE1("MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF,
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim "Maximum number of idle children"),
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jimAP_INIT_TAKE1("MaxClients", set_max_clients, NULL, RSRC_CONF,
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe "Maximum number of children alive at the same time"),
d52b01101efdd3a37493d1090f20eb23c4dd1521wroweAP_INIT_TAKE1("ServerLimit", set_server_limit, NULL, RSRC_CONF,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "Maximum value of MaxClients for this run of Apache"),
d52b01101efdd3a37493d1090f20eb23c4dd1521wroweAP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND,
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe{ NULL }
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe};
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingmodule AP_MODULE_DECLARE_DATA mpm_prefork_module = {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MPM20_MODULE_STUFF,
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm ap_mpm_rewrite_args, /* hook to run before apache parses args */
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm NULL, /* create per-directory config structure */
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm NULL, /* merge per-directory config structures */
de8799b6a9e8221681873ab5a81b6af6596faaafwrowe NULL, /* create per-server config structure */
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm NULL, /* merge per-server config structures */
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm prefork_cmds, /* command apr_table_t */
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm prefork_hooks, /* register hooks */
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm};
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm