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
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.
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.
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/* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT. We want
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * some sort of compile-time limit to help catch typos.
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe/* config globals */
38fd849bd99e2765ee633b6dc576b5f17acdc455wroweint ap_threads_per_child=0; /* Worker threads per child */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int server_limit = 0;
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowestatic int first_server_limit = 0;
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.
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.).
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic int one_process = 0;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestatic apr_pool_t *pchild; /* Pool for httpd child stuff */
9621e4c4056383e4a2b844b14687bae500b33a82wrowestatic pid_t ap_my_pid; /* it seems silly to call getpid all the time */
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe#endif /* TPF */
4c67ef499845a08771e81254ce6eb2324a160bc7wrowestatic volatile int die_now = 0;
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
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowestatic void chdir_for_gprof(void)
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe ap_get_module_config(ap_server_conf->module_config, &core_module);
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe const char *use_dir;
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe use_dir = ap_server_root_relative(pconf, buf ? buf : dir);
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
4415d997ac73262e513c0a571bd5be4f609040bawrowe ap_log_error(APLOG_MARK, APLOG_ERR, res, ap_server_conf,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe use_dir = ap_server_root_relative(pconf, DEFAULT_REL_RUNTIMEDIR);
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/* a clean exit from a child with proper cleanup */
4415d997ac73262e513c0a571bd5be4f609040bawrowestatic void clean_child_exit(int code) __attribute__ ((noreturn));
4415d997ac73262e513c0a571bd5be4f609040bawrowestatic void accept_mutex_on(void)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *msg = "couldn't grab the accept mutex";
00211b036b78699ace57a6d800a52e6c2d57652fnd ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, NULL, "%s", msg);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "%s", msg);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic void accept_mutex_off(void)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard apr_status_t rv = apr_proc_mutex_unlock(accept_mutex);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard const char *msg = "couldn't release the accept mutex";
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
a812b025d139f465a31c76fc02ed162ed5271b03nd ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, "%s", msg);
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.
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next) {stmt;}} while(0)
00211b036b78699ace57a6d800a52e6c2d57652fndAP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq/*****************************************************************
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Connection structures and accounting...
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* For a graceful stop, we want the child to exit when done */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* volatile just in case */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int volatile shutdown_pending;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int volatile restart_pending;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int volatile is_graceful;
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/* restart() is the signal handler for SIGHUP and AP_SIG_GRACEFUL
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * in the parent process, unless running in ONE_PROCESS mode
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Probably not an error - don't bother reporting it */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void set_signals(void)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (sigaction(AP_SIG_GRACEFUL_STOP, &sa, NULL) < 0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
22d348febc3c258df246ac93e37945398dbf0348ianh ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * processing one
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGXCPU */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGXFSZ */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGHUP */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* AP_SIG_GRACEFUL */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* AP_SIG_GRACEFUL */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGPIPE */
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.
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic int num_listensocks = 0;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* not ever called anymore... */
45dac0729754e413ff7c673481b219e9ab1a11f1bnicholes mpm_state = AP_MPMQ_STARTING; /* for benefit of any hooks that run as this
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * child initializes
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* Get a sub context for global allocations in this child, so that
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * we can have cleanups occur when the child exits.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_allocator_max_free_set(allocator, ap_max_mem_free);
68ce856106f153813339db8670f6cd0ab8dea484minfrin apr_pool_create_ex(&pchild, pconf, NULL, allocator);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* needs to be done before we switch UIDs so we have permissions */
11c3b5180e1de6776035320b012a28bb146e7b46chuck status = apr_proc_mutex_child_init(&accept_mutex, ap_lock_fname, pchild);
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_log_error(APLOG_MARK, APLOG_EMERG, status, ap_server_conf,
11c3b5180e1de6776035320b012a28bb146e7b46chuck "Couldn't initialize cross-process lock in child "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_create_sb_handle(&sbh, pchild, my_child_num, 0);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Set up the pollfd array */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* ### check the status */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) apr_pollset_create(&pollset, num_listensocks, pchild, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (lr = ap_listeners, i = num_listensocks; i--; lr = lr->next) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* ### check the status */
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 * (Re)initialize this child to a pre-connection state.
5babe00918c88eda487771fa6d6d4a1a19c0ced0chuck && requests_this_child++ >= ap_max_requests_per_child)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe * Wait for an acceptable connection to arrive.
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* Lock around "accept", if necessary */
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* There is only one listener record, so refer to that one. */
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin /* multiple listening sockets - need to poll */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* timeout == -1 == wait forever */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard status = apr_pollset_poll(pollset, -1, &numdesc, &pdesc);
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.
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.
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 * ### hmm... this descriptor might have POLLERR rather
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * ### than POLLIN
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* if we accept() something we don't want to die, so we have to
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * defer the exit
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* resource shortage or should-not-occur occured */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * We now have a connection, so set it up with the appropriate
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * socket options, file descriptors, and read/write buffers.
d75bc22ab2702fa770f6935f07107efff16a76f0wrowe current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd, my_child_num, sbh, bucket_alloc);
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.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (ap_mpm_pod_check(pod) == APR_SUCCESS) { /* selected as idle? */
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?
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* Don't catch AP_SIG_GRACEFUL in ONE_PROCESS mode :) */
9865751743e928ea0a9ad83faa04a738001932deminfrin (void) ap_update_child_status_from_indexes(slot, 0, SERVER_STARTING,
c1c0628ca9788908a5fc7502d04a89c348b75ee6wrowe /* BS2000 requires a "special" version of fork() before a setuid() call */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "fork: Unable to fork new process");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* fork didn't succeed. Fix the scoreboard or else
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * it will say SERVER_STARTING forever and ever
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status_from_indexes(slot, 0, SERVER_DEAD,
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.
a812b025d139f465a31c76fc02ed162ed5271b03nd return -1;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* by default AIX binds to a single processor
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe * this bit unbinds children which will then bind to another cpu
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int status = bindprocessor(BINDPROCESS, (int)getpid(),
af952917c05e56874069e1e5f64e6473bb478b68minfrin ap_server_conf, "processor unbind failed %d", status);
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* Disable the parent's signal handlers and set up proper handling in
4a7df15077ff65dbf3b2cf68fa3063273ac0a547minfrin * the child.
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* The child process just closes listeners on AP_SIG_GRACEFUL.
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * The pod is used for signalling the graceful restart.
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe/* start up a bunch of children */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq for (i = 0; number_to_start && i < ap_daemons_limit; ++i) {
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq if (ap_scoreboard_image->servers[i][0].status != SERVER_DEAD) {
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.
af952917c05e56874069e1e5f64e6473bb478b68minfrinstatic void perform_idle_server_maintenance(apr_pool_t *p)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* initialize the free_list */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe for (i = 0; i < ap_daemons_limit; ++i) {
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (i >= ap_max_daemons_limit && free_length == idle_spawn_rate)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* try to keep children numbers as low as possible */
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.
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).
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
9379749d811388a7d0e3410940ddd6743a33d330jim /* terminate the free list */
9379749d811388a7d0e3410940ddd6743a33d330jim /* only report this condition once */
9379749d811388a7d0e3410940ddd6743a33d330jim static int reported = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
24efed0910118b762a4eb84830875d4714b8d315ianh "server reached MaxClients setting, consider"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " raising the MaxClients setting");
9379749d811388a7d0e3410940ddd6743a33d330jim "server seems busy, (you may need "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "to increase StartServers, or Min/MaxSpareServers), "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "spawning %d children, there are %d idle, and "
9379749d811388a7d0e3410940ddd6743a33d330jim for (i = 0; i < free_length; ++i) {
9379749d811388a7d0e3410940ddd6743a33d330jim ap_log_error(APLOG_MARK, APLOG_EMERG, 0, ap_server_conf,
9379749d811388a7d0e3410940ddd6743a33d330jim "No active child processes: shutting down");
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe#endif /* TPF */
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
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe/*****************************************************************
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * Executive routines.
5d5c9e862c3d4e7f15c12d293de4111f52404760wroweint ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* Initialize cross-process accept lock */
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_lock_fname = apr_psprintf(_pconf, "%s.%" APR_PID_T_FMT,
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe rv = apr_proc_mutex_create(&accept_mutex, ap_lock_fname,
75b0a6a06ca1f4de80e3dd2a09c9f0c7d0a56089wrowe "Couldn't create accept lock (%s) (%d)",
4415d997ac73262e513c0a571bd5be4f609040bawrowe "Couldn't set permissions on cross-process lock; "
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe "check User and Group directives");
446c6a9a1e1073798258f1237f8c848b5f917b66wrowe if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {
de274dca1be855ebb66bb7857951aae26fcb54c7wrowe /* fix the generation number in the global score; we just got a new,
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * cleared scoreboard
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe ap_scoreboard_image->global->running_generation = ap_my_generation;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_daemons_max_free < ap_daemons_min_free + 1) /* Don't thrash... */
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.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (remaining_children_to_start > ap_daemons_limit) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* give the system some time to recover before kicking into
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * exponential mode
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq "%s configured -- resuming normal operations",
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq "AcceptMutex: %s (default: %s)",
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* this is a memory leak, but I'll fix it later. */
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
a812b025d139f465a31c76fc02ed162ed5271b03nd processed_status = ap_process_child_status(&pid, exitwhy, status);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* non-fatal death... note that it's gone in the scoreboard. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status_from_indexes(child_slot, 0, SERVER_DEAD,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* child detected a resource shortage (E[NM]FILE, ENOBUFS, etc)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * cut the fork rate to the minimum
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* we're still doing a 1-for-1 replacement of dead
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * children with new children
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard else if (apr_proc_other_child_alert(&pid, APR_OC_REASON_DEATH, status) == APR_SUCCESS) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* handled */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Great, we've probably just lost a slot in the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * scoreboard. Somehow we don't know about this
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "long lost child came home! (pid %ld)", (long)pid.pid);
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 /* 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 /* 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 shutdown_pending = os_check_server(tpf_server_name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif /*TPF */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } /* one_process */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Time to shut down:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Kill child processes, tell them to call child_exit, etc...
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_reclaim_child_processes(1); /* Start with SIGTERM */
1cde33c7e2019830f8fb3224e01649305583916etrawick /* cleanup pid file on normal shutdown */
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb pidfile = ap_server_root_relative (pconf, ap_pid_fname);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard "removed PID file %s (pid=%ld)",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard "caught SIGTERM, shutting down");
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.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Stop listening */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* kill off the idle ones */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Send SIGUSR1 to the active children */
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 /* Allow each child which actually finished to exit */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* cleanup pid file */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pidfile = ap_server_root_relative (pconf, ap_pid_fname);
af952917c05e56874069e1e5f64e6473bb478b68minfrin "removed PID file %s (pid=%ld)",
4a7df15077ff65dbf3b2cf68fa3063273ac0a547minfrin ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh "caught " AP_SIG_GRACEFUL_STOP_STRING ", shutting down gracefully");
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh /* Don't really exit until each child has finished */
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh /* Pause for a second */
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh /* Relieve any children which have now exited */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_mpm_safe_kill(MPM_CHILD_PID(index), 0) == APR_SUCCESS) {
11c3b5180e1de6776035320b012a28bb146e7b46chuck /* Having just one child is enough to stay around */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (!ap_graceful_shutdown_timeout || apr_time_now() < cutoff));
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.
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin /* we've been told to restart */
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin /* not worth thinking about */
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 ap_scoreboard_image->global->running_generation = ap_my_generation;
35c9e4d2c0a6465746a98958ef756114834461e6minfrin ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard "Graceful restart requested, doing restart");
35c9e4d2c0a6465746a98958ef756114834461e6minfrin /* kill off the idle ones */
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 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 * 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.
4224d5789080ea5586d49420da1e1996f5653bb5ianh ap_mpm_safe_kill(ap_scoreboard_image->parent[index].pid, AP_SIG_GRACEFUL);
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb /* Kill 'em off */
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGHUP");
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/* 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.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int prefork_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding static int restart_num = 0;
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* the reverse of pre_config, we want this only the first time around */
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim if (restart_num++ == 0) {
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim if ((num_listensocks = ap_setup_listeners(ap_server_conf)) < 1) {
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim "no listening sockets available, shutting down");
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim "could not open pipe-of-death");
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowestatic int prefork_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe static int restart_num = 0;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* sigh, want this only the second time around */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "apr_proc_detach failed");
433dc2d5dae74ed067db6175010ff973d02511e9jerenkrantz ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowestatic int prefork_check_config(apr_pool_t *p, apr_pool_t *plog,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe static int restart_num = 0;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* the reverse of pre_config, we want this only the first time around */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if (restart_num++ == 0) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "WARNING: ServerLimit of %d exceeds compile-time "
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe " %d servers, decreasing to %d.",
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe "ServerLimit of %d exceeds compile-time limit "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "of %d, decreasing to match",
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
4cc02d7521758b07c7cd240e8ea32fb7a20909cfwrowe "WARNING: ServerLimit of %d not allowed, "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "ServerLimit of %d not allowed, increasing to 1",
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* you cannot change ServerLimit across a restart; ignore
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe * any such attempts
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* don't need a startup console version here */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "changing ServerLimit to %d from original value of %d "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "not allowed during restart",
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "WARNING: MaxClients of %d exceeds ServerLimit "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe " %d servers, decreasing MaxClients to %d.",
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe " To increase, please see the ServerLimit "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "directive.");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "MaxClients of %d exceeds ServerLimit value "
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "of %d, decreasing to match",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "WARNING: MaxClients of %d not allowed, "
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "MaxClients of %d not allowed, increasing to 1",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* ap_daemons_to_start > ap_daemons_limit checked in ap_mpm_run() */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "WARNING: StartServers of %d not allowed, "
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "StartServers of %d not allowed, increasing to 1",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "WARNING: MinSpareServers of %d not allowed, "
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 "MinSpareServers of %d not allowed, increasing to 1",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* ap_daemons_max_free < ap_daemons_min_free + 1 checked in ap_mpm_run() */
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 static const char *const aszSucc[] = {"core.c", NULL};
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 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);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic const char *set_min_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic const char *set_max_free_servers(cmd_parms *cmd, void *dummy, const char *arg)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbbstatic const char *set_max_clients (cmd_parms *cmd, void *dummy, const char *arg)
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrinstatic const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)
35c9e4d2c0a6465746a98958ef756114834461e6minfrin const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
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"),
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingmodule AP_MODULE_DECLARE_DATA mpm_prefork_module = {
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm ap_mpm_rewrite_args, /* hook to run before apache parses args */