prefork.c revision 4e0e544abc732ca30b5f58c387a93d877cf51e24
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq/* ====================================================================
78cd48acd325773619d78ac0d7263a99a8922faend * The Apache Software License, Version 1.1
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Copyright (c) 2000 The Apache Software Foundation. All rights
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * reserved.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Redistribution and use in source and binary forms, with or without
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * modification, are permitted provided that the following conditions
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 2. Redistributions in binary form must reproduce the above copyright
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * notice, this list of conditions and the following disclaimer in
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the documentation and/or other materials provided with the
7708bd70088b64148d7d78fd84ede43ced63c713minfrin * distribution.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 3. The end-user documentation included with the redistribution,
36a72c96fc2dda27eadbae8a108fa428cc1419c1wrowe * if any, must include the following acknowledgment:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * "This product includes software developed by the
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm * Apache Software Foundation (http://www.apache.org/)."
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe * Alternately, this acknowledgment may appear in the software itself,
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe * if and wherever such third-party acknowledgments normally appear.
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe * 4. The names "Apache" and "Apache Software Foundation" must
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe * not be used to endorse or promote products derived from this
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe * software without prior written permission. For written
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe * permission, please contact apache@apache.org.
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick * 5. Products derived from this software may not be called "Apache",
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick * nor may "Apache" appear in their name, without prior written
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick * permission of the Apache Software Foundation.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * SUCH DAMAGE.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ====================================================================
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This software consists of voluntary contributions made by many
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * individuals on behalf of the Apache Software Foundation. For more
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * information on the Apache Software Foundation, please see
a812b025d139f465a31c76fc02ed162ed5271b03nd * Portions of this software are based upon public domain software
a812b025d139f465a31c76fc02ed162ed5271b03nd * originally written at the National Center for Supercomputing Applications,
a812b025d139f465a31c76fc02ed162ed5271b03nd * University of Illinois, Urbana-Champaign.
a812b025d139f465a31c76fc02ed162ed5271b03nd * httpd.c: simple http daemon for answering WWW file requests
a812b025d139f465a31c76fc02ed162ed5271b03nd * 03-21-93 Rob McCool wrote original code (up to NCSA HTTPd 1.3)
a812b025d139f465a31c76fc02ed162ed5271b03nd * 03-06-95 blong
00211b036b78699ace57a6d800a52e6c2d57652fnd * changed server number for child-alone processes to 0 and changed name
00211b036b78699ace57a6d800a52e6c2d57652fnd * of processes
a812b025d139f465a31c76fc02ed162ed5271b03nd * 03-10-95 blong
a812b025d139f465a31c76fc02ed162ed5271b03nd * Added numerous speed hacks proposed by Robert S. Thau (rst@ai.mit.edu)
a812b025d139f465a31c76fc02ed162ed5271b03nd * including set group before fork, and call gettime before to fork
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * to set up libraries.
a812b025d139f465a31c76fc02ed162ed5271b03nd * 04-14-95 rst / rh
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * Brandon's code snarfed from NCSA 1.4, but tinkered to work with the
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * Apache server, and also to have child processes do accept() directly.
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * April-July '95 rst
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * Extensive rework for Apache.
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe/* TODO: this is a cobbled together prefork MPM example... it should mostly
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * TODO: behave like apache-1.3... here's a short list of things I think
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * TODO: need cleaning up still:
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe * TODO: - clean up scoreboard stuff when we figure out how to do it in 2.0
4c67ef499845a08771e81254ce6eb2324a160bc7wrowe#include <bstring.h> /* for IRIX, FD_SET calls bzero() */
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe/* config globals */
4415d997ac73262e513c0a571bd5be4f609040bawrowestatic const char *ap_lock_fname;
4415d997ac73262e513c0a571bd5be4f609040bawrowestatic int ap_extended_status = 0;
4415d997ac73262e513c0a571bd5be4f609040bawrowe * The max child slot ever assigned, preserved across restarts. Necessary
4415d997ac73262e513c0a571bd5be4f609040bawrowe * to deal with MaxClients changes across SIGUSR1 restarts. We use this
4415d997ac73262e513c0a571bd5be4f609040bawrowe * value to optimize routines that have to scan the entire scoreboard.
4415d997ac73262e513c0a571bd5be4f609040bawrowe/* *Non*-shared http_main globals... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* one_process --- debugging mode variable; can be set from the command line
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * with the -X flag. If set, this gets you the child_main loop running
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * in the process which originally started up (no detach, no make_child),
00211b036b78699ace57a6d800a52e6c2d57652fnd * which is a pretty nice debugging environment. (You'll get a SIGHUP
a812b025d139f465a31c76fc02ed162ed5271b03nd * early in standalone_main; just continue through. This is the server
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * trying to kill off any child processes which it might have lying
00211b036b78699ace57a6d800a52e6c2d57652fnd * around --- Apache doesn't keep track of their pids, it just sends
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * SIGHUP to the process group, ignoring it in the root process.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * Continue through and you'll be fine.).
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int one_process = 0;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic ap_pool_t *pconf; /* Pool for config stuff */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic ap_pool_t *pchild; /* Pool for httpd child stuff */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardint ap_my_pid; /* it seems silly to call getpid all the time */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#endif /* TPF */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * change directory for gprof to plop the gmon.out file
a812b025d139f465a31c76fc02ed162ed5271b03nd * configure in httpd.conf:
a812b025d139f465a31c76fc02ed162ed5271b03nd * GprofDir logs/ -> $ServerRoot/logs/gmon.out
a812b025d139f465a31c76fc02ed162ed5271b03nd * GprofDir logs/% -> $ServerRoot/logs/gprof.$pid/gmon.out
a812b025d139f465a31c76fc02ed162ed5271b03ndstatic void chdir_for_gprof(void)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_get_module_config(ap_server_conf->module_config, &core_module);
00211b036b78699ace57a6d800a52e6c2d57652fnd ap_snprintf(buf, sizeof(buf), "%sgprof.%d", dir, (int)getpid());
00211b036b78699ace57a6d800a52e6c2d57652fnd dir = ap_server_root_relative(pconf, buf[0] ? buf : dir);
00211b036b78699ace57a6d800a52e6c2d57652fnd ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* XXX - I don't know if TPF will ever use this module or not, so leave
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the ap_check_signals calls in but disable them - manoj */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* a clean exit from a child with proper cleanup */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void clean_child_exit(int code) __attribute__ ((noreturn));
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* XXXX possibly bogus cast */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_server_root_relative(p, ap_lock_fname), (unsigned long)getpid());
16d38ac65d7e54cd44eeda7b23f84ee68b35094ewrowe/* Initialize mutex lock.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Done by each child at its birth
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_child_init_lock(&accept_lock, ap_lock_fname, p);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard/* Initialize mutex lock.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * Must be safe to call this on a restart.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard rv = ap_create_lock(&accept_lock, APR_MUTEX, APR_CROSS_PROCESS, ap_lock_fname, p);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "couldn't create accept mutex");
33cb45dc8c5106018b7c2f6ae42478b109423e0eniqstatic void accept_mutex_on(void)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniqstatic void accept_mutex_off(void)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq/* 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
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * multiple Listen statements. Define SINGLE_LISTEN_UNSERIALIZED_ACCEPT
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * when it's safe in the single Listen case.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next) {stmt;}} while(0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *fname;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding fname = ap_server_root_relative(p, ap_scoreboard_fname);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_shm_init(&scoreboard_shm, SCOREBOARD_SIZE + NEW_SCOREBOARD_SIZE + 40, fname, p) != APR_SUCCESS) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard",
22d348febc3c258df246ac93e37945398dbf0348ianh ap_scoreboard_image = ap_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
22d348febc3c258df246ac93e37945398dbf0348ianh ap_new_scoreboard_image = ap_shm_malloc(scoreboard_shm, NEW_SCOREBOARD_SIZE);
a812b025d139f465a31c76fc02ed162ed5271b03nd ap_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_register_cleanup(p, NULL, cleanup_shared_mem, ap_null_cleanup);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_scoreboard_image->global.running_generation = 0;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe/* Called by parent process */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard running_gen = ap_scoreboard_image->global.running_generation;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_scoreboard_image->global.running_generation = running_gen;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe/* Routines called to deal with the scoreboard image
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * --- note that we do *not* need write locks, since update_child_status
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * only updates a *single* record in place, and only one process writes to
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * a given scoreboard slot at a time (either the child process owning that
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * slot, or the parent, noting that the child has died).
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * As a final note --- setting the score entry to getpid() is always safe,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * since when the parent is writing an entry, it's only noting SERVER_DEAD
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe force_read(scoreboard_fd, ap_scoreboard_image, sizeof(*ap_scoreboard_image))
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowestatic ap_inline void put_scoreboard_info(int child_num,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe lseek(scoreboard_fd, (long) child_num * sizeof(short_score), 0);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe force_write(scoreboard_fd, new_score_rec, sizeof(short_score));
33cb45dc8c5106018b7c2f6ae42478b109423e0eniqint ap_update_child_status(int child_num, int status, request_rec *r)
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * Reset individual counters
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin ap_cpystrn(ss->client, ap_get_remote_host(c, r->per_dir_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_cpystrn(ss->request, "NULL", sizeof(ss->request));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_cpystrn(ss->request, r->the_request, sizeof(ss->request));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Don't reveal the password in the server-status view */
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_cpystrn(ss->request, ap_pstrcat(r->pool, r->method, " ",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_unparse_uri_components(r->pool, &r->parsed_uri, UNP_OMITPASSWORD),
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* clean up the slot's vhostrec pointer (maybe re-used)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * and mark the slot as belonging to a new generation.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_scoreboard_image->parent[child_num].generation = ap_my_generation;
d7387fcd4969206172e3a2a8bbcd25a3d7011ac5rbb lseek(scoreboard_fd, XtOffsetOf(scoreboard, parent[child_num]), 0);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard force_write(scoreboard_fd, &ap_scoreboard_image->parent[child_num],
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void update_scoreboard_global(void)
b999f6ba2a266bf9a92687f31bb7e76021ac5891ianh (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard force_write(scoreboard_fd, &ap_scoreboard_image->global,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardvoid ap_time_process_request(int child_num, int status)
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void increment_counts(int child_num, request_rec *r)
35c9e4d2c0a6465746a98958ef756114834461e6minfrin long int bs = 0;
5a5a6c22260854843c973e2ea9a14bec64362ab5wrowe short_score *ss;
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_sync_scoreboard_image();
35c9e4d2c0a6465746a98958ef756114834461e6minfrin ss = &ap_scoreboard_image->servers[child_num];
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (r->sent_bodyct)
11c3b5180e1de6776035320b012a28bb146e7b46chuck ap_bgetopt(r->connection->client, BO_BYTECT, &bs);
35c9e4d2c0a6465746a98958ef756114834461e6minfrin#ifdef HAVE_TIMES
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard times(&ss->times);
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin ss->access_count++;
e2b2e15108eb7cb566b1d70ce4e479276d951de5minfrin ss->my_access_count++;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ss->conn_count++;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ss->bytes_served += (unsigned long) bs;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ss->my_bytes_served += (unsigned long) bs;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ss->conn_bytes += (unsigned long) bs;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard put_scoreboard_info(child_num, ss);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard for (i = 0; i < ap_max_daemons_limit; ++i)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard if (ap_scoreboard_image->parent[i].pid == pid->pid)
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard Systems without a real waitpid sometimes lose a child's exit while waiting
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard for another. Search through the scoreboard for missing children.
3d350b6e1cb11fa790a6adb428856b5dd9857fecianh for (n = 0; n < ap_max_daemons_limit; ++n) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ap_scoreboard_image->servers[n].status != SERVER_DEAD &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) {
409f0f53a83313c59f1b227ed0a340adc1081e88wrowe /* just mark it as having a successful exit status */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard/* handle all varieties of core dumping signals */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* At this point we've got sig blocked, because we're still inside
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the signal handler. When we leave the signal handler it will
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * be unblocked, and we'll take the signal... and coredump or whatever
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * is appropriate for this particular Unix. In addition the parent
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * will see the real signal we received -- whereas if we called
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * abort() here, the parent would only see SIGABRT.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*****************************************************************
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * Connection structures and accounting...
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int volatile deferred_die;
002bcf949b064d7c042465d1095cafcfc6c9b701wrowestatic int volatile usr1_just_die;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard/* volatile just in case */
9379749d811388a7d0e3410940ddd6743a33d330jimstatic int volatile shutdown_pending;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int volatile restart_pending;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddardstatic int volatile is_graceful;
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* Um, is this _probably_ not an error, if the user has
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * tried to do a shutdown twice quickly, so we won't
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * worry about reporting it.
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin /* Probably not an error - don't bother reporting it */
1cde33c7e2019830f8fb3224e01649305583916etrawickstatic void set_signals(void)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGSEGV)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGBUS)");
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABORT)");
9b4c60b689b8a3f2d48d19c55d857b276d405f85wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABRT)");
a812b025d139f465a31c76fc02ed162ed5271b03nd ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGILL)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* we want to ignore HUPs and USR1 while we're busy processing one */
af952917c05e56874069e1e5f64e6473bb478b68minfrin 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(SIGUSR1)");
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#endif /* SIGBUS */
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq#endif /* SIGABORT */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGABRT */
af952917c05e56874069e1e5f64e6473bb478b68minfrin#endif /* SIGILL */
af952917c05e56874069e1e5f64e6473bb478b68minfrin#endif /* SIGXCPU */
35c9e4d2c0a6465746a98958ef756114834461e6minfrin#endif /* SIGXFSZ */
af952917c05e56874069e1e5f64e6473bb478b68minfrin#endif /* SIGHUP */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe#endif /* SIGUSR1 */
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 srv;
9379749d811388a7d0e3410940ddd6743a33d330jim ap_scoreboard_image->global.running_generation != ap_my_generation) {
3c59b18ce62f97468aaa5951d4e21a5478ef36ecminfrin /* Get a sub context for global allocations in this child, so that
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * we can have cleanups occur when the child exits.
9379749d811388a7d0e3410940ddd6743a33d330jim /* needs to be done before we switch UIDs so we have permissions */
9379749d811388a7d0e3410940ddd6743a33d330jim (void) ap_update_child_status(my_child_num, SERVER_READY, (request_rec *) NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Stop Ctrl-C/Ctrl-Break signals going to child processes */
24efed0910118b762a4eb84830875d4714b8d315ianh unsigned long ulTimes;
9379749d811388a7d0e3410940ddd6743a33d330jim /* Prepare to receive a SIGUSR1 due to graceful restart so that
9379749d811388a7d0e3410940ddd6743a33d330jim * we can exit cleanly.
9379749d811388a7d0e3410940ddd6743a33d330jim * (Re)initialize this child to a pre-connection state.
9379749d811388a7d0e3410940ddd6743a33d330jim && requests_this_child++ >= ap_max_requests_per_child)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status(my_child_num, SERVER_READY, (request_rec *) NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Wait for an acceptable connection to arrive.
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* Lock around "accept", if necessary */
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* more than one socket */
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe srv = select(listenmaxfd + 1, &main_fds, NULL, NULL, NULL);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* Single Unix documents select as returning errnos
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * EBADF, EINTR, and EINVAL... and in none of those
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * cases does it make sense to continue. In fact
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * on Linux 2.0.x we seem to end up with EFAULT
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * occasionally, and we'd loop forever due to it.
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf, "select: (listen)");
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* we remember the last_lr we searched last time around so that
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe we don't end up starving any particular listening socket */
4415d997ac73262e513c0a571bd5be4f609040bawrowe /* FIXME: if we get here, something bad has happened, and we're
4415d997ac73262e513c0a571bd5be4f609040bawrowe probably gonna spin forever.
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* only one socket, just pretend we did the other stuff */
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* if we accept() something we don't want to die, so we have to
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * defer the exit
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* we didn't get a socket, and we were told to die */
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb break; /* We have a socket ready for reading */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* TODO: this accept result handling stuff should be abstracted...
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * it's already out of date between the various unix mpms
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Our old behaviour here was to continue after accept()
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * errors. But this leads us into lots of troubles
529005244758297d4415aa912c67a67f805349bcianh * because most of the errors are quite fatal. For
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * example, EMFILE can be caused by slow descriptor
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * leaks (say in a 3rd party module, or libc). It's
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * foolish for us to continue after an EMFILE. We also
529005244758297d4415aa912c67a67f805349bcianh * seem to tickle kernel bugs on some platforms which
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * lead to never-ending loops here. So it seems best
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * to just exit in most cases.
529005244758297d4415aa912c67a67f805349bcianh switch (stat) {
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard /* EPROTO on certain older kernels really means
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * ECONNABORTED, so we need to ignore it for them.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * See discussion in new-httpd archives nh.9701
529005244758297d4415aa912c67a67f805349bcianh * search for EPROTO.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Also see nh.9603, search for EPROTO:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * There is potentially a bug in Solaris 2.x x<6,
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * and other boxes that implement tcp sockets in
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * userland (i.e. on top of STREAMS). On these
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * systems, EPROTO can actually result in a fatal
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * loop. See PR#981 for example. It's hard to
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * handle both uses of EPROTO.
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq /* Linux generates the rest of these, other tcp
a812b025d139f465a31c76fc02ed162ed5271b03nd * stacks (i.e. bsd) tend to hide them behind
a812b025d139f465a31c76fc02ed162ed5271b03nd * getsockopt() interfaces. They occur when
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * the net goes sour or the client disconnects
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * after the three-way handshake has been done
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * in the kernel but before userland has picked
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * up the socket.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * When the network layer has been shut down, there
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * is not much use in simply exiting: the parent
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * would simply re-create us (and we'd fail again).
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Use the CHILDFATAL code to tear the server down.
a6314dfa8dd8a0d69db16288581e4950a2dd3955minfrin * @@@ Martin's idea for possible improvement:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * A different approach would be to define
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * a new APEXIT_NETDOWN exit code, the reception
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * of which would make the parent shutdown all
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * children, then idle-loop until it detected that
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the network is up again, and restart the children.
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * Ben Hyde noted that temporary ENETDOWN situations
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * occur in mobile IP.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_EMERG, stat, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "ap_accept: giving up.");
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard#endif /*ENETDOWN*/
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_log_error(APLOG_MARK, APLOG_EMERG, stat, ap_server_conf,
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard "offload device inactive");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_ERR, stat, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "ap_accept: (client socket)");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We've got a socket, let's at least process one request off the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * socket before we accept a graceful restart request. We set
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the signal to ignore because we don't want to disturb any
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * third party code.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * We now have a connection, so set it up with the appropriate
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * socket options, file descriptors, and read/write buffers.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "new file descriptor %d is too large; you probably need "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "to rebuild Apache with a larger FD_SETSIZE "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "(currently %d)",
1cde33c7e2019830f8fb3224e01649305583916etrawick (void) ap_update_child_status(my_child_num, SERVER_BUSY_READ,
1cde33c7e2019830f8fb3224e01649305583916etrawick current_conn = ap_new_apr_connection(ptrans, ap_server_conf, conn_io, csd,
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int make_child(server_rec *s, int slot, time_t now)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status(slot, SERVER_STARTING, (request_rec *) NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* BS2000 requires a "special" version of fork() before a setuid() call */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((pid = os_fork(unixd_config.user_name)) == -1) {
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
af952917c05e56874069e1e5f64e6473bb478b68minfrin * it will say SERVER_STARTING forever and ever
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (void) ap_update_child_status(slot, SERVER_DEAD, (request_rec *) NULL);
4a7df15077ff65dbf3b2cf68fa3063273ac0a547minfrin /* In case system resources are maxxed out, we don't want
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh Apache running away with the CPU trying to fork over and
ff1234e45aca1b8171d711ecb87f58b9d9100a99ianh over and over again. */
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh/* by default AIX binds to a single processor
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh * this bit unbinds children which will then bind to another cpu
fd3fa792f04fc9c4e8f5f83dceb0fc34e71f8570ianh ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, ap_server_conf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Disable the restart signal handlers and enable the just_die stuff.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Note that since restart() just notes that a restart has been
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * requested there's no race condition here.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding lseek(scoreboard_fd, XtOffsetOf(scoreboard, parent[slot]), 0);
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin force_write(scoreboard_fd, &ap_scoreboard_image->parent[slot],
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin/* start up a bunch of children */
35c9e4d2c0a6465746a98958ef756114834461e6minfrin for (i = 0; number_to_start && i < ap_daemons_limit; ++i) {
35c9e4d2c0a6465746a98958ef756114834461e6minfrin if (ap_scoreboard_image->servers[i].status != SERVER_DEAD) {
4224d5789080ea5586d49420da1e1996f5653bb5ianh * idle_spawn_rate is the number of children that will be spawned on the
4224d5789080ea5586d49420da1e1996f5653bb5ianh * next maintenance cycle if there aren't enough idle servers. It is
4224d5789080ea5586d49420da1e1996f5653bb5ianh * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
4224d5789080ea5586d49420da1e1996f5653bb5ianh * without the need to spawn.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* initialize the free_list */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard for (i = 0; i < ap_daemons_limit; ++i) {
af952917c05e56874069e1e5f64e6473bb478b68minfrin if (i >= ap_max_daemons_limit && free_length == idle_spawn_rate)
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* try to keep children numbers as low as possible */
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* We consider a starting server as idle because we started it
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * at least a cycle ago, and if it still hasn't finished starting
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * then we're just going to swamp things worse by forking more.
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * So we hopefully won't need to fork more if we count it.
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * This depends on the ordering of SERVER_READY and SERVER_STARTING.
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* always kill the highest numbered child if we have to...
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * no really well thought out reason ... other than observing
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * the server behaviour under linux where lower numbered children
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * tend to service more hits (and hence are more likely to have
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim * their data in cpu caches).
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* kill off one child... we use SIGUSR1 because that'll cause it to
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe * shut down gracefully, in case it happened to pick up a request
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe * while we were counting
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe kill(ap_scoreboard_image->parent[to_kill].pid, SIGUSR1);
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe /* terminate the free list */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* only report this condition once */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe static int reported = 0;
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, ap_server_conf,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "server reached MaxClients setting, consider"
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe " raising the MaxClients setting");
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, ap_server_conf,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "server seems busy, (you may need "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "to increase StartServers, or Min/MaxSpareServers), "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "spawning %d children, there are %d idle, and "
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe for (i = 0; i < free_length; ++i) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe if(make_child(ap_server_conf, free_slots[i], now) == -1) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, ap_server_conf,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "No active child processes: shutting down");
7bcd3f64532e7da74ad6bd4a9b1cbdf52bdee068wrowe#endif /* TPF */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe /* the next time around we want to spawn twice as many if this
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe * wasn't good enough, but not if we've just done a graceful
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, 0, s,
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe "no listening sockets available, shutting down");
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe/* Useful to erase the status of children that might be from previous
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe * generations */
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowestatic void ap_prefork_force_reset_connection_status(long conn_id)
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe for (i = 0; i < STATUSES_PER_CONNECTION; i++) {
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_new_scoreboard_image->table[conn_id][i].key[0] = '\0';
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe/*****************************************************************
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * Executive routines.
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwroweint ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_scoreboard_fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe if (ap_daemons_max_free < ap_daemons_min_free + 1) /* Don't thrash... */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* If we're doing a graceful_restart then we're going to see a lot
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * of children exiting immediately when we get into the main loop
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * below (because we just sent them SIGUSR1). This happens pretty
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * rapidly... and for each one that exits we'll start a new one until
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * we reach at least daemons_min_free. But we may be permitted to
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * start more than that, so we'll just keep track of how many we're
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * supposed to start up without the 1 second penalty between each fork.
e6c244ee56578707b20a86e0e938498299a93b6cnd /* give the system some time to recover before kicking into
e6c244ee56578707b20a86e0e938498299a93b6cnd * exponential mode */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe "%s configured -- resuming normal operations",
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, ap_server_conf,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* this is a memory leak, but I'll fix it later. */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* XXX: if it takes longer than 1 second for all our children
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard * to start up and get into IDLE state then we may spawn an
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * extra child
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* non-fatal death... note that it's gone in the scoreboard. */
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard ap_prefork_force_reset_connection_status(child_slot);
e6366481b8fe06a24337f0b30b7da66cf64d6062stoddard (void) ap_update_child_status(child_slot, SERVER_DEAD,
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* we're still doing a 1-for-1 replacement of dead
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * children with new children
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe /* handled */
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb /* Great, we've probably just lost a slot in the
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * scoreboard. Somehow we don't know about this
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe "long lost child came home! (pid %ld)", (long)pid.pid);
93aa7afe1af831ee8b23aa0d97323c388e3fb8d3ianh /* Don't perform idle maintenance when a child dies,
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * only do it when there's a timeout. Remember only a
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq * finite number of children can die, and it's pretty
a812b025d139f465a31c76fc02ed162ed5271b03nd * pathological for a lot to die suddenly.
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb /* we hit a 1 second timeout in which none of the previous
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * generation of children needed to be reaped... so assume
afef080e47ef499a5cbceb7ad7fadbb3abca0b48minfrin * they're all done, and pick up the slack if any is left.
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb /* In any event we really shouldn't do the code below because
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * few of the servers we just started are in the IDLE state
a2f9f38db0931e6edf7b71378dd680c3c5fa5841rbb * yet, so we'd mistakenly create an extra server.
4224d5789080ea5586d49420da1e1996f5653bb5ianh#endif /*TPF */
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim /* Time to gracefully shut down:
5d5c9e862c3d4e7f15c12d293de4111f52404760wrowe * Kill child processes, tell them to call child_exit, etc...
d52b01101efdd3a37493d1090f20eb23c4dd1521wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_reclaim_child_processes(1); /* Start with SIGTERM */
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm /* cleanup pid file on normal shutdown */
de8799b6a9e8221681873ab5a81b6af6596faaafwrowe pidfile = ap_server_root_relative (pconf, ap_pid_fname);
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm "removed PID file %s (pid=%ld)",
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm "caught SIGTERM, shutting down");
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm /* we've been told to restart */
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm /* not worth thinking about */
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm /* advance to the next generation */
e1d00c81dc34e2c644cc936b9dea75ec9ccfca2adougm /* XXX: we really need to make sure this new generation number isn't in
e1d00c81dc34e2c644cc936b9dea75ec9ccfca2adougm * use by any of the children.
621bd763d2e4d32f19013ac8b76b375b5a01851fdougm ap_scoreboard_image->global.running_generation = ap_my_generation;
65aeb4185d6a108b19c27b89f311dc57dab62239nd ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
65aeb4185d6a108b19c27b89f311dc57dab62239nd "SIGUSR1 received. Doing graceful restart");
134330b92fbc39045b7e56654f4c252fb7c53803nd /* kill off the idle ones */
134330b92fbc39045b7e56654f4c252fb7c53803nd ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGUSR1");
fdacf528f0125e0165de42b7783b1dcbf961a189chuck /* This is mostly for debugging... so that we know what is still
fdacf528f0125e0165de42b7783b1dcbf961a189chuck * gracefully dealing with existing request. But we can't really
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe * do it if we're in a SCOREBOARD_FILE because it'll cause
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe * corruption too easily.
fdacf528f0125e0165de42b7783b1dcbf961a189chuck for (i = 0; i < ap_daemons_limit; ++i) {
65aeb4185d6a108b19c27b89f311dc57dab62239nd if (ap_scoreboard_image->servers[i].status != SERVER_DEAD) {
33cb45dc8c5106018b7c2f6ae42478b109423e0eniq ap_scoreboard_image->servers[i].status = SERVER_GRACEFUL;
5babe00918c88eda487771fa6d6d4a1a19c0ced0chuck /* Kill 'em off */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGHUP");
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_reclaim_child_processes(0); /* Not when just starting up */
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
11c3b5180e1de6776035320b012a28bb146e7b46chuck "SIGHUP received. Attempting to restart");
d75bc22ab2702fa770f6935f07107efff16a76f0wrowestatic void prefork_pre_config(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp)
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin static int restart_num = 0;
2e41eca72bcc4167d1871b0941ee79845540d58eminfrin /* sigh, want this only the second time around */
67f62b7a48ff9eb8d9f31898dceaf9f89280a723dougm ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
ap_extended_status = 0;
static void prefork_hooks(void)
INIT_SIGLIST();
#ifdef AUX3
(void) set42sig();
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
if (ap_daemons_min_free <= 0) {
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
const char *fname;
return err;
return NULL;
while (i < STATUSES_PER_CONNECTION) {
return NULL;
long *array_slot;
for (i = 0; i < ap_max_daemons_limit; i++) {
*array_slot = i;
return connection_list;
char **array_slot;
while (i < STATUSES_PER_CONNECTION) {
return key_list;
const char *value)
if (!maintain_connection_status) return;
while (i < STATUSES_PER_CONNECTION) {
if (i >= STATUSES_PER_CONNECTION) {
for (i = 0; i < ap_max_daemons_limit; i++) {
for (j = 0; j < STATUSES_PER_CONNECTION; j++) {
return server_status;
{ NULL }