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