spmt_os2.c revision 87e0da4e1eabf35b0b2a48a9290c5e725854de8f
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz/* ====================================================================
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * Copyright (c) 2000 The Apache Software Foundation. All rights
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * reserved.
71da3cca78eea6010f89b139ecadb79e6d213c4fnd *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * are met:
71da3cca78eea6010f89b139ecadb79e6d213c4fnd *
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * 1. Redistributions of source code must retain the above copyright
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * notice, this list of conditions and the following disclaimer.
71da3cca78eea6010f89b139ecadb79e6d213c4fnd *
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the documentation and/or other materials provided with the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 3. The end-user documentation included with the redistribution,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * if any, must include the following acknowledgment:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * "This product includes software developed by the
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * Apache Software Foundation (http://www.apache.org/)."
952023a04a2f9d51553babd9094fb857f1c97548trawick * Alternately, this acknowledgment may appear in the software itself,
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * if and wherever such third-party acknowledgments normally appear.
1b21d7b3d97def358b2e923655edeb16613a1c31gstein *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * 4. The names "Apache" and "Apache Software Foundation" must
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * not be used to endorse or promote products derived from this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * software without prior written permission. For written
f4c310fd2555c6faca1f980f00b161eadb089023gstein * permission, please contact apache@apache.org.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 5. Products derived from this software may not be called "Apache",
f4c310fd2555c6faca1f980f00b161eadb089023gstein * nor may "Apache" appear in their name, without prior written
f4c310fd2555c6faca1f980f00b161eadb089023gstein * permission of the Apache Software Foundation.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
f4c310fd2555c6faca1f980f00b161eadb089023gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
f4c310fd2555c6faca1f980f00b161eadb089023gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
f4c310fd2555c6faca1f980f00b161eadb089023gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
f4c310fd2555c6faca1f980f00b161eadb089023gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
f4c310fd2555c6faca1f980f00b161eadb089023gstein * SUCH DAMAGE.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ====================================================================
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * This software consists of voluntary contributions made by many
f4c310fd2555c6faca1f980f00b161eadb089023gstein * individuals on behalf of the Apache Software Foundation. For more
f4c310fd2555c6faca1f980f00b161eadb089023gstein * information on the Apache Software Foundation, please see
5b03ba47ff7225cacb131f14b019332af27da960gstein * <http://www.apache.org/>.
5b03ba47ff7225cacb131f14b019332af27da960gstein *
5b03ba47ff7225cacb131f14b019332af27da960gstein * Portions of this software are based upon public domain software
5b03ba47ff7225cacb131f14b019332af27da960gstein * originally written at the National Center for Supercomputing Applications,
5b03ba47ff7225cacb131f14b019332af27da960gstein * University of Illinois, Urbana-Champaign.
5b03ba47ff7225cacb131f14b019332af27da960gstein */
5b03ba47ff7225cacb131f14b019332af27da960gstein
5b03ba47ff7225cacb131f14b019332af27da960gstein#define CORE_PRIVATE
5b03ba47ff7225cacb131f14b019332af27da960gstein#define INCL_DOS
5b03ba47ff7225cacb131f14b019332af27da960gstein#define INCL_DOSERRORS
5b03ba47ff7225cacb131f14b019332af27da960gstein
5b03ba47ff7225cacb131f14b019332af27da960gstein#include "ap_config.h"
5b03ba47ff7225cacb131f14b019332af27da960gstein#include "httpd.h"
5b03ba47ff7225cacb131f14b019332af27da960gstein#include "mpm_default.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "http_main.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "http_log.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "http_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_core.h" /* for get_remote_host */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#include "http_connection.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "scoreboard.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_mpm.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_listen.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "iol_socket.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_portable.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <os2.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <stdlib.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <sys/signal.h>
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe/* config globals */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int ap_max_requests_per_child=0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic char *ap_pid_fname=NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int ap_daemons_to_start=0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int ap_daemons_min_free=0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int ap_daemons_max_free=0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int ap_daemons_limit=0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic time_t ap_restart_time=0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int ap_extended_status = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The max child slot ever assigned, preserved across restarts. Necessary
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * to deal with MaxClients changes across SIGUSR1 restarts. We use this
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * value to optimize routines that have to scan the entire scoreboard.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int max_daemons_limit = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic char ap_coredump_dir[MAX_STRING_LEN];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* *Non*-shared http_main globals... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic server_rec *server_conf;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe/* one_process --- debugging mode variable; can be set from the command line
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * with the -X flag. If set, this gets you the child_main loop running
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * 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
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * early in standalone_main; just continue through. This is the server
f4c310fd2555c6faca1f980f00b161eadb089023gstein * trying to kill off any child processes which it might have lying
f4c310fd2555c6faca1f980f00b161eadb089023gstein * around --- Apache doesn't keep track of their pids, it just sends
f4c310fd2555c6faca1f980f00b161eadb089023gstein * SIGHUP to the process group, ignoring it in the root process.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Continue through and you'll be fine.).
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowestatic int one_process = 0;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_pool_t *pconf; /* Pool for config stuff */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic scoreboard *ap_scoreboard_image = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstruct thread_globals {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int child_num;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pool_t *pchild; /* Pool for httpd child stuff */
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe int usr1_just_die;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe};
f4c310fd2555c6faca1f980f00b161eadb089023gstein
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowskistatic struct thread_globals **ppthread_globals = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define THREAD_GLOBAL(gvar) ((*ppthread_globals)->gvar)
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid reinit_scoreboard(ap_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image == NULL) {
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image == NULL) {
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowski ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Ouch! Out of memory reiniting scoreboard!");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowevoid cleanup_scoreboard(void)
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_assert(ap_scoreboard_image);
f4c310fd2555c6faca1f980f00b161eadb089023gstein free(ap_scoreboard_image);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* a clean exit from a child with proper cleanup */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void clean_child_exit(int code)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (THREAD_GLOBAL(pchild)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_destroy_pool(THREAD_GLOBAL(pchild));
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->servers[THREAD_GLOBAL(child_num)].thread_retval = code;
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz _endthread();
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz}
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_lock_t *accept_mutex = NULL;
91644a5f4d3e992dc208304b50e80bbb236fca89trawick
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougmstatic ap_status_t accept_mutex_child_cleanup(void *foo)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_unlock(accept_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm/*
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Initialize mutex lock.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Done by each child at it's birth
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void accept_mutex_child_init(ap_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_register_cleanup(p, NULL, accept_mutex_child_cleanup, ap_null_cleanup);
48f35e10f195dd594d75738fc536bb885eda537cgstein}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe/*
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Initialize mutex lock.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Must be safe to call this on a restart.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
48f35e10f195dd594d75738fc536bb885eda537cgsteinstatic void accept_mutex_init(ap_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_status_t rc = ap_create_lock(&accept_mutex, APR_MUTEX, APR_INTRAPROCESS, NULL, p);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (rc != APR_SUCCESS) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_EMERG, rc, server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Error creating accept lock. Exiting!");
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgsteinstatic void accept_mutex_on(void)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_status_t rc = ap_lock(accept_mutex);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein if (rc != APR_SUCCESS) {
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_log_error(APLOG_MARK, APLOG_EMERG, rc, server_conf,
48f35e10f195dd594d75738fc536bb885eda537cgstein "Error getting accept lock. Exiting!");
48f35e10f195dd594d75738fc536bb885eda537cgstein clean_child_exit(APEXIT_CHILDFATAL);
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
7b6ba9c468f26bdb3492d5e8cb79628a3b04e8c8wrowestatic void accept_mutex_off(void)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_status_t rc = ap_unlock(accept_mutex);
48f35e10f195dd594d75738fc536bb885eda537cgstein
24efed0910118b762a4eb84830875d4714b8d315ianh if (rc != APR_SUCCESS) {
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_log_error(APLOG_MARK, APLOG_EMERG, rc, server_conf,
48f35e10f195dd594d75738fc536bb885eda537cgstein "Error freeing accept lock. Exiting!");
48f35e10f195dd594d75738fc536bb885eda537cgstein clean_child_exit(APEXIT_CHILDFATAL);
48f35e10f195dd594d75738fc536bb885eda537cgstein }
c1b808d160bfb5c849263be8d4acff600853a328trawick}
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein/* On some architectures it's safe to do unserialized accept()s in the single
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein * Listen case. But it's never safe to do it in the case where there's
48f35e10f195dd594d75738fc536bb885eda537cgstein * multiple Listen statements. Define SINGLE_LISTEN_UNSERIALIZED_ACCEPT
48f35e10f195dd594d75738fc536bb885eda537cgstein * when it's safe in the single Listen case.
48f35e10f195dd594d75738fc536bb885eda537cgstein */
48f35e10f195dd594d75738fc536bb885eda537cgstein#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
48f35e10f195dd594d75738fc536bb885eda537cgstein#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next) {stmt;}} while(0)
48f35e10f195dd594d75738fc536bb885eda537cgstein#else
48f35e10f195dd594d75738fc536bb885eda537cgstein#define SAFE_ACCEPT(stmt) do {stmt;} while(0)
48f35e10f195dd594d75738fc536bb885eda537cgstein#endif
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgsteinAPI_EXPORT(int) ap_exists_scoreboard_image(void)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
48f35e10f195dd594d75738fc536bb885eda537cgstein return (ap_scoreboard_image ? 1 : 0);
48f35e10f195dd594d75738fc536bb885eda537cgstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_update_child_status(int child_num, int status, request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int old_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein short_score *ss;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (child_num < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ss = &ap_scoreboard_image->servers[child_num];
f4c310fd2555c6faca1f980f00b161eadb089023gstein old_status = ss->status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ss->status = status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_extended_status) {
48f35e10f195dd594d75738fc536bb885eda537cgstein if (status == SERVER_READY || status == SERVER_DEAD) {
48f35e10f195dd594d75738fc536bb885eda537cgstein /*
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Reset individual counters
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ss->my_access_count = 0L;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ss->my_bytes_served = 0L;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ss->conn_count = (unsigned short) 0;
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein ss->conn_bytes = (unsigned long) 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (r) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe conn_rec *c = r->connection;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_cpystrn(ss->client, ap_get_remote_host(c, r->per_dir_config,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe REMOTE_NOLOOKUP), sizeof(ss->client));
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->the_request == NULL) {
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein ap_cpystrn(ss->request, "NULL", sizeof(ss->request));
f4c310fd2555c6faca1f980f00b161eadb089023gstein } else if (r->parsed_uri.password == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_cpystrn(ss->request, r->the_request, sizeof(ss->request));
f4c310fd2555c6faca1f980f00b161eadb089023gstein } else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Don't reveal the password in the server-status view */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_cpystrn(ss->request, ap_pstrcat(r->pool, r->method, " ",
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm ap_unparse_uri_components(r->pool, &r->parsed_uri, UNP_OMITPASSWORD),
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->assbackwards ? NULL : " ", r->protocol, NULL),
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(ss->request));
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ss->vhostrec = r->server;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f958dac1550254a59b45f4655138bb34dad5e76egstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == SERVER_STARTING && r == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* clean up the slot's vhostrec pointer (maybe re-used)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and mark the slot as belonging to a new generation.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ss->vhostrec = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->parent[child_num].generation = ap_scoreboard_image->global.running_generation;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return old_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantzvoid ap_time_process_request(int child_num, int status)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein short_score *ss;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_time_t tms_blk;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (child_num < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz ss = &ap_scoreboard_image->servers[child_num];
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == START_PREQUEST) {
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe ss->start_time = ap_now();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (status == STOP_PREQUEST) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ss->stop_time = ap_now();
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* TODO: call me some time */
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic void increment_counts(int child_num, request_rec *r)
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe{
f39230a531b23d94f86a087963299bbe2e431a4agstein long int bs = 0;
f39230a531b23d94f86a087963299bbe2e431a4agstein short_score *ss;
f39230a531b23d94f86a087963299bbe2e431a4agstein
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe ss = &ap_scoreboard_image->servers[child_num];
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe
f39230a531b23d94f86a087963299bbe2e431a4agstein if (r->sent_bodyct)
f39230a531b23d94f86a087963299bbe2e431a4agstein ap_bgetopt(r->connection->client, BO_BYTECT, &bs);
f39230a531b23d94f86a087963299bbe2e431a4agstein
1e2133fe37e6cbcd683233057ef62236bc8e5826trawick#ifdef HAVE_TIMES
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein times(&ss->times);
f39230a531b23d94f86a087963299bbe2e431a4agstein#endif
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ss->access_count++;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ss->my_access_count++;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ss->conn_count++;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ss->bytes_served += (unsigned long) bs;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ss->my_bytes_served += (unsigned long) bs;
f39230a531b23d94f86a087963299bbe2e431a4agstein ss->conn_bytes += (unsigned long) bs;
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int find_child_by_tid(int tid)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein{
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein int i;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein for (i = 0; i < max_daemons_limit; ++i)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (ap_scoreboard_image->parent[i].tid == tid)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return i;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return -1;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein}
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein/* Finally, this routine is used by the caretaker thread to wait for
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * a while...
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein/* number of calls to wait_or_timeout between writable probes */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein#ifndef INTERVAL_OF_WRITABLE_PROBES
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein#define INTERVAL_OF_WRITABLE_PROBES 10
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein#endif
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int wait_or_timeout_counter;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int wait_or_timeout(ap_wait_t *status)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein int ret;
f39230a531b23d94f86a087963299bbe2e431a4agstein ULONG tid;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein ++wait_or_timeout_counter;
f39230a531b23d94f86a087963299bbe2e431a4agstein if (wait_or_timeout_counter == INTERVAL_OF_WRITABLE_PROBES) {
f39230a531b23d94f86a087963299bbe2e431a4agstein wait_or_timeout_counter = 0;
f39230a531b23d94f86a087963299bbe2e431a4agstein#ifdef APR_HAS_OTHER_CHILD
f39230a531b23d94f86a087963299bbe2e431a4agstein ap_probe_writable_fds();
f39230a531b23d94f86a087963299bbe2e431a4agstein#endif
f39230a531b23d94f86a087963299bbe2e431a4agstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein tid = 0;
f39230a531b23d94f86a087963299bbe2e431a4agstein ret = DosWaitThread(&tid, DCWW_NOWAIT);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein if (ret == 0) {
f39230a531b23d94f86a087963299bbe2e431a4agstein int child_num = find_child_by_tid(tid);
f39230a531b23d94f86a087963299bbe2e431a4agstein ap_assert( child_num > 0 );
f39230a531b23d94f86a087963299bbe2e431a4agstein *status = ap_scoreboard_image->servers[child_num].thread_retval;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return tid;
f39230a531b23d94f86a087963299bbe2e431a4agstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein DosSleep(SCOREBOARD_MAINTENANCE_INTERVAL / 1000);
f39230a531b23d94f86a087963299bbe2e431a4agstein return -1;
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein#if defined(NSIG)
f39230a531b23d94f86a087963299bbe2e431a4agstein#define NumSIG NSIG
f39230a531b23d94f86a087963299bbe2e431a4agstein#elif defined(_NSIG)
f39230a531b23d94f86a087963299bbe2e431a4agstein#define NumSIG _NSIG
f39230a531b23d94f86a087963299bbe2e431a4agstein#elif defined(__NSIG)
f39230a531b23d94f86a087963299bbe2e431a4agstein#define NumSIG __NSIG
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#else
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#define NumSIG 32 /* for 1998's unixes, this is still a good assumption */
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
6810bf1570bed88d16239b27ce47d48408bb2e51gstein#ifdef SYS_SIGLIST /* platform has sys_siglist[] */
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#define INIT_SIGLIST() /*nothing*/
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#else /* platform has no sys_siglist[], define our own */
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#define SYS_SIGLIST ap_sys_siglist
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#define INIT_SIGLIST() siglist_init();
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gsteinconst char *ap_sys_siglist[NumSIG];
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gsteinstatic void siglist_init(void)
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein{
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein int sig;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[0] = "Signal 0";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGHUP
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGHUP] = "Hangup";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGINT
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGINT] = "Interrupt";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGQUIT
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGQUIT] = "Quit";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGILL
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGILL] = "Illegal instruction";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGTRAP
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGTRAP] = "Trace/BPT trap";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGIOT
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGIOT] = "IOT instruction";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGABRT
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGABRT] = "Abort";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGEMT
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGEMT] = "Emulator trap";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGFPE
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGFPE] = "Arithmetic exception";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGKILL
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGKILL] = "Killed";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGBUS
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGBUS] = "Bus error";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGSEGV
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGSEGV] = "Segmentation fault";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGSYS
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGSYS] = "Bad system call";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGPIPE
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGPIPE] = "Broken pipe";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGALRM
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGALRM] = "Alarm clock";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe#ifdef SIGTERM
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_sys_siglist[SIGTERM] = "Terminated";
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#endif
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein#ifdef SIGUSR1
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGUSR1] = "User defined signal 1";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGUSR2
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGUSR2] = "User defined signal 2";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGCLD
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGCLD] = "Child status change";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGCHLD
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGCHLD] = "Child status change";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPWR
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGPWR] = "Power-fail restart";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz#ifdef SIGWINCH
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGWINCH] = "Window changed";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGURG
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_sys_siglist[SIGURG] = "urgent socket condition";
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPOLL
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGPOLL] = "Pollable event occurred";
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGIO
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGIO] = "socket I/O possible";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGSTOP
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGSTOP] = "Stopped (signal)";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGTSTP
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_sys_siglist[SIGTSTP] = "Stopped";
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGCONT
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_sys_siglist[SIGCONT] = "Continued";
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGTTIN
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_sys_siglist[SIGTTIN] = "Stopped (tty input)";
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGTTOU
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_sys_siglist[SIGTTOU] = "Stopped (tty output)";
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGVTALRM
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGVTALRM] = "virtual timer expired";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPROF
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGPROF] = "profiling timer expired";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXCPU
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGXCPU] = "exceeded cpu limit";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXFSZ
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sys_siglist[SIGXFSZ] = "exceeded file size limit";
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (sig=0; sig < sizeof(ap_sys_siglist)/sizeof(ap_sys_siglist[0]); ++sig)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_sys_siglist[sig] == NULL)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_sys_siglist[sig] = "";
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* platform has sys_siglist[] */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* handle all varieties of core dumping signals */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic void sig_coredump(int sig)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein chdir(ap_coredump_dir);
f4c310fd2555c6faca1f980f00b161eadb089023gstein signal(sig, SIG_DFL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein kill(getpid(), sig);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* At this point we've got sig blocked, because we're still inside
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the signal handler. When we leave the signal handler it will
f4c310fd2555c6faca1f980f00b161eadb089023gstein * be unblocked, and we'll take the signal... and coredump or whatever
f4c310fd2555c6faca1f980f00b161eadb089023gstein * is appropriate for this particular Unix. In addition the parent
f4c310fd2555c6faca1f980f00b161eadb089023gstein * will see the real signal we received -- whereas if we called
f4c310fd2555c6faca1f980f00b161eadb089023gstein * abort() here, the parent would only see SIGABRT.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Connection structures and accounting...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void just_die(int sig)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic void usr1_handler(int sig)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (THREAD_GLOBAL(usr1_just_die)) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe just_die(sig);
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz }
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz ap_scoreboard_image->parent[THREAD_GLOBAL(child_num)].deferred_die = 1;
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz}
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz/* volatile just in case */
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantzstatic int volatile shutdown_pending;
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantzstatic int volatile restart_pending;
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantzstatic int volatile is_graceful;
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantzstatic void sig_term(int sig)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (shutdown_pending == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Um, is this _probably_ not an error, if the user has
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * tried to do a shutdown twice quickly, so we won't
f4c310fd2555c6faca1f980f00b161eadb089023gstein * worry about reporting it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein shutdown_pending = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void restart(int sig)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (restart_pending == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Probably not an error - don't bother reporting it */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein restart_pending = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein is_graceful = sig == SIGUSR1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void set_signals(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifndef NO_USE_SIGACTION
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct sigaction sa;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sigemptyset(&sa.sa_mask);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = sig_coredump;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(SA_ONESHOT)
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = SA_ONESHOT;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#elif defined(SA_RESETHAND)
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = SA_RESETHAND;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGSEGV, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGSEGV)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGBUS
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGBUS, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGBUS)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABORT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGABORT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGABORT)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABRT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGABRT, &sa, NULL) < 0)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGABRT)");
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowski#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGILL
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm if (sigaction(SIGILL, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGILL)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = sig_term;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGTERM, &sa, NULL) < 0)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGTERM)");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGINT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGINT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGINT)");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGXCPU
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sa.sa_handler = SIG_DFL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (sigaction(SIGXCPU, &sa, NULL) < 0)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGXCPU)");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGXFSZ
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sa.sa_handler = SIG_DFL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (sigaction(SIGXFSZ, &sa, NULL) < 0)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGXFSZ)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPIPE
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = SIG_IGN;
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm if (sigaction(SIGPIPE, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGPIPE)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we want to ignore HUPs and USR1 while we're busy processing one */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sigaddset(&sa.sa_mask, SIGHUP);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sigaddset(&sa.sa_mask, SIGUSR1);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sa.sa_handler = restart;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (sigaction(SIGHUP, &sa, NULL) < 0)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGHUP)");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (sigaction(SIGUSR1, &sa, NULL) < 0)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf, "sigaction(SIGUSR1)");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#else
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (!one_process) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGSEGV, sig_coredump);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGBUS
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGBUS, sig_coredump);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGBUS */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGABORT
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGABORT, sig_coredump);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGABORT */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGABRT
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGABRT, sig_coredump);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGABRT */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGILL
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGILL, sig_coredump);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGILL */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGXCPU
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGXCPU, SIG_DFL);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGXCPU */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGXFSZ
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGXFSZ, SIG_DFL);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGXFSZ */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGTERM, sig_term);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGHUP
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGHUP, restart);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGHUP */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGUSR1
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGUSR1, restart);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGUSR1 */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGPIPE
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGPIPE, SIG_IGN);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif /* SIGPIPE */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic void sock_disable_nagle(ap_socket_t *s)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* The Nagle algorithm says that we should delay sending partial
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * packets in hopes of getting more data. We don't want to do
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * this; we are not telnet. There are bad interactions between
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * persistent connections and Nagle's algorithm that have very severe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * performance penalties. (Failing to disable Nagle is not much of a
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * problem with simple HTTP.)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe *
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * In spite of these problems, failure here is not a shooting offense.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int just_say_no = 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_status_t status;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe status = ap_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &just_say_no, sizeof(int));
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (status != APR_SUCCESS) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, status, server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "setsockopt: (TCP_NODELAY)");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#else
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#define sock_disable_nagle(s) /* NOOP */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe/*****************************************************************
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Child process main loop.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wroweAPI_EXPORT(void) ap_child_terminate(request_rec *r)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe r->connection->keepalive = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_scoreboard_image->parent[THREAD_GLOBAL(child_num)].deferred_die = 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wroweint ap_graceful_stop_signalled(void)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ap_scoreboard_image->parent[THREAD_GLOBAL(child_num)].deferred_die ||
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_scoreboard_image->global.running_generation != ap_scoreboard_image->parent[THREAD_GLOBAL(child_num)].generation) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return 0;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_stop_signalled(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (shutdown_pending || restart_pending ||
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->parent[THREAD_GLOBAL(child_num)].deferred_die ||
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_scoreboard_image->global.running_generation != ap_scoreboard_image->parent[THREAD_GLOBAL(child_num)].generation) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int setup_listeners(ap_pool_t *pchild, ap_pollfd_t **listen_poll)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_listen_rec *lr;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int numfds = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (lr = ap_listeners; lr; lr = lr->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein numfds++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_setup_poll(listen_poll, numfds, pchild);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (lr = ap_listeners; lr; lr = lr->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_add_poll_socket(*listen_poll, lr->sd, APR_POLLIN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic void child_main(void *child_num_arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *lr = NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_listen_rec *first_lr = NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_pool_t *ptrans;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe conn_rec *current_conn;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_iol *iol;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_pool_t *pchild;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe parent_score *sc_parent_rec;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int requests_this_child = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_pollfd_t *listen_poll;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_socket_t *csd = NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int nsds, rv;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* Disable the restart signal handlers and enable the just_die stuff.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Note that since restart() just notes that a restart has been
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * requested there's no race condition here.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe set_signals(); /* signals aren't inherrited by child threads */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGHUP, just_die);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGUSR1, just_die);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGTERM, just_die);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* Get a sub pool for global allocations in this child, so that
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * we can have cleanups occur when the child exits.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_create_pool(&pchild, pconf);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe *ppthread_globals = (struct thread_globals *)ap_palloc(pchild, sizeof(struct thread_globals));
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe THREAD_GLOBAL(child_num) = (int)child_num_arg;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sc_parent_rec = ap_scoreboard_image->parent + THREAD_GLOBAL(child_num);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe THREAD_GLOBAL(pchild) = pchild;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_create_pool(&ptrans, pchild);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (setup_listeners(pchild, &listen_poll)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* needs to be done before we switch UIDs so we have permissions */
f4c310fd2555c6faca1f980f00b161eadb089023gstein SAFE_ACCEPT(accept_mutex_child_init(pchild));
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_init_hook(pchild, server_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm (void) ap_update_child_status(THREAD_GLOBAL(child_num), SERVER_READY, (request_rec *) NULL);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGHUP, just_die);
f4c310fd2555c6faca1f980f00b161eadb089023gstein signal(SIGTERM, just_die);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!ap_stop_signalled()) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein BUFF *conn_io;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int srv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_socket_t *sd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Prepare to receive a SIGUSR1 due to graceful restart so that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we can exit cleanly.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein THREAD_GLOBAL(usr1_just_die) = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein signal(SIGUSR1, usr1_handler);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * (Re)initialize this child to a pre-connection state.
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein current_conn = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_clear_pool(ptrans);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((ap_max_requests_per_child > 0
f4c310fd2555c6faca1f980f00b161eadb089023gstein && requests_this_child++ >= ap_max_requests_per_child)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) ap_update_child_status(THREAD_GLOBAL(child_num), SERVER_READY, (request_rec *) NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Wait for an acceptable connection to arrive.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Lock around "accept", if necessary */
f4c310fd2555c6faca1f980f00b161eadb089023gstein SAFE_ACCEPT(accept_mutex_on());
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_stop_signalled()) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (;;) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_listeners->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* more than one socket */
f4c310fd2555c6faca1f980f00b161eadb089023gstein srv = ap_poll(listen_poll, &nsds, -1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (srv != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Single Unix documents select as returning errnos
f4c310fd2555c6faca1f980f00b161eadb089023gstein * EBADF, EINTR, and EINVAL... and in none of those
f4c310fd2555c6faca1f980f00b161eadb089023gstein * cases does it make sense to continue. In fact
f4c310fd2555c6faca1f980f00b161eadb089023gstein * on Linux 2.0.x we seem to end up with EFAULT
f4c310fd2555c6faca1f980f00b161eadb089023gstein * occasionally, and we'd loop forever due to it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, errno, server_conf, "select: (listen)");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe clean_child_exit(1);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we remember the last_lr we searched last time around so that
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe we don't end up starving any particular listening socket */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (first_lr == NULL) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe first_lr = ap_listeners;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe lr = first_lr;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe do {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_int16_t event;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (!lr) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe lr = ap_listeners;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_get_revents(&event, lr->sd, listen_poll);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (event == APR_POLLIN) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein first_lr = lr->next;
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein lr = lr->next;
f4c310fd2555c6faca1f980f00b161eadb089023gstein } while (lr != first_lr);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (lr == first_lr) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sd = lr->sd;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* only one socket, just pretend we did the other stuff */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sd = ap_listeners->sd;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* if we accept() something we don't want to die, so we have to
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * defer the exit
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
f4c310fd2555c6faca1f980f00b161eadb089023gstein THREAD_GLOBAL(usr1_just_die) = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = ap_accept(&csd, sd, ptrans);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (rv == APR_SUCCESS)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe break; /* We have a socket ready for reading */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Our old behaviour here was to continue after accept()
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * errors. But this leads us into lots of troubles
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * because most of the errors are quite fatal. For
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * 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
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * lead to never-ending loops here. So it seems best
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * to just exit in most cases.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe switch (ap_canonical_error(rv)) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef EPROTO
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* EPROTO on certain older kernels really means
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ECONNABORTED, so we need to ignore it for them.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * See discussion in new-httpd archives nh.9701
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * search for EPROTO.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe *
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Also see nh.9603, search for EPROTO:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * There is potentially a bug in Solaris 2.x x<6,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * and other boxes that implement tcp sockets in
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * userland (i.e. on top of STREAMS). On these
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * systems, EPROTO can actually result in a fatal
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * loop. See PR#981 for example. It's hard to
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * handle both uses of EPROTO.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein case EPROTO:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef ECONNABORTED
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ECONNABORTED:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Linux generates the rest of these, other tcp
f4c310fd2555c6faca1f980f00b161eadb089023gstein * stacks (i.e. bsd) tend to hide them behind
f4c310fd2555c6faca1f980f00b161eadb089023gstein * getsockopt() interfaces. They occur when
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the net goes sour or the client disconnects
f4c310fd2555c6faca1f980f00b161eadb089023gstein * after the three-way handshake has been done
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in the kernel but before userland has picked
f4c310fd2555c6faca1f980f00b161eadb089023gstein * up the socket.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef ECONNRESET
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ECONNRESET:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef ETIMEDOUT
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe case ETIMEDOUT:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef EHOSTUNREACH
f4c310fd2555c6faca1f980f00b161eadb089023gstein case EHOSTUNREACH:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef ENETUNREACH
f4c310fd2555c6faca1f980f00b161eadb089023gstein case ENETUNREACH:
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein case EINTR:
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We only get hit by an EINTR if the parent is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * killing us off
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein default:
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, rv, server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "accept: (client socket)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ap_stop_signalled()) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe clean_child_exit(0);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe THREAD_GLOBAL(usr1_just_die) = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein SAFE_ACCEPT(accept_mutex_off()); /* unlock after "accept" */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We've got a socket, let's at least process one request off the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * socket before we accept a graceful restart request. We set
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the signal to ignore because we don't want to disturb any
f4c310fd2555c6faca1f980f00b161eadb089023gstein * third party code.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein signal(SIGUSR1, SIG_IGN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We now have a connection, so set it up with the appropriate
f4c310fd2555c6faca1f980f00b161eadb089023gstein * socket options, file descriptors, and read/write buffers.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein sock_disable_nagle(csd);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe iol = os2_attach_socket(csd);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (iol == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "error attaching to socket");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_close_socket(csd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) ap_update_child_status(THREAD_GLOBAL(child_num), SERVER_BUSY_READ,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *) NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein conn_io = ap_bcreate(ptrans, B_RDWR);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_bpush_iol(conn_io, iol);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe current_conn = ap_new_apr_connection(ptrans, server_conf, conn_io, csd,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe THREAD_GLOBAL(child_num));
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_process_connection(current_conn);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_lingering_close(current_conn);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe clean_child_exit(0);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int make_child(server_rec *s, int slot, time_t now)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe TID tid;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (slot + 1 > max_daemons_limit) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe max_daemons_limit = slot + 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (one_process) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe struct thread_globals *parent_globals = *ppthread_globals;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGHUP, just_die);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGINT, just_die);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SIGQUIT
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGQUIT, SIG_DFL);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGTERM, just_die);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe child_main((void *)slot);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe *ppthread_globals = parent_globals;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_update_child_status(slot, SERVER_STARTING, (request_rec *) NULL);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if ((tid = _beginthread(child_main, NULL, 256*1024, (void *)slot)) == -1) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s, "_beginthread: Unable to create new thread");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz /* _beginthread didn't succeed. Fix the scoreboard or else
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz * it will say SERVER_STARTING forever and ever
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz */
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz (void) ap_update_child_status(slot, SERVER_DEAD, (request_rec *) NULL);
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz /* In case system resources are maxxed out, we don't want
0fad1368edb71b1411d6d00684900e5d2a6e6b78jerenkrantz Apache running away with the CPU trying to _beginthread over and
0df0055470838140d9797dd186b2fdbe67edcc57jorton over and over again. */
0df0055470838140d9797dd186b2fdbe67edcc57jorton sleep(10);
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz return -1;
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz }
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz
0fad1368edb71b1411d6d00684900e5d2a6e6b78jerenkrantz ap_scoreboard_image->parent[slot].tid = tid;
0df0055470838140d9797dd186b2fdbe67edcc57jorton return 0;
0df0055470838140d9797dd186b2fdbe67edcc57jorton}
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz/* start up a bunch of children */
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantzstatic void startup_children(int number_to_start)
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz{
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz int i;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe time_t now = time(0);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe for (i = 0; number_to_start && i < ap_daemons_limit; ++i) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ap_scoreboard_image->servers[i].status != SERVER_DEAD) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe continue;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (make_child(server_conf, i, now) < 0) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe break;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe --number_to_start;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe/*
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * idle_spawn_rate is the number of children that will be spawned on the
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * next maintenance cycle if there aren't enough idle servers. It is
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * without the need to spawn.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int idle_spawn_rate = 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifndef MAX_SPAWN_RATE
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#define MAX_SPAWN_RATE (32)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int hold_off_on_exponential_spawning;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic void perform_idle_server_maintenance(void)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int i;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int to_kill;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int idle_count;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe short_score *ss;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe time_t now = time(0);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int free_length;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int free_slots[MAX_SPAWN_RATE];
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int last_non_dead;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int total_non_dead;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* initialize the free_list */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe free_length = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe to_kill = -1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe idle_count = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe last_non_dead = -1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe total_non_dead = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe for (i = 0; i < ap_daemons_limit; ++i) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int status;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (i >= max_daemons_limit && free_length == idle_spawn_rate)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe break;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ss = &ap_scoreboard_image->servers[i];
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe status = ss->status;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (status == SERVER_DEAD) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* try to keep children numbers as low as possible */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (free_length < idle_spawn_rate) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe free_slots[free_length] = i;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ++free_length;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* We consider a starting server as idle because we started it
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * at least a cycle ago, and if it still hasn't finished starting
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * then we're just going to swamp things worse by forking more.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * So we hopefully won't need to fork more if we count it.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * This depends on the ordering of SERVER_READY and SERVER_STARTING.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (status <= SERVER_READY) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ++ idle_count;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* always kill the highest numbered child if we have to...
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * no really well thought out reason ... other than observing
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * the server behaviour under linux where lower numbered children
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * tend to service more hits (and hence are more likely to have
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * their data in cpu caches).
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe to_kill = i;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ++total_non_dead;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe last_non_dead = i;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe max_daemons_limit = last_non_dead + 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (idle_count > ap_daemons_max_free) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* kill off one child... we use SIGUSR1 because that'll cause it to
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * shut down gracefully, in case it happened to pick up a request
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * while we were counting
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_scoreboard_image->parent[to_kill].deferred_die = 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe idle_spawn_rate = 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else if (idle_count < ap_daemons_min_free) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* terminate the free list */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (free_length == 0) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* only report this condition once */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe static int reported = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!reported) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "server reached MaxClients setting, consider"
f4c310fd2555c6faca1f980f00b161eadb089023gstein " raising the MaxClients setting");
f4c310fd2555c6faca1f980f00b161eadb089023gstein reported = 1;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein }
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein idle_spawn_rate = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (idle_spawn_rate >= 8) {
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, 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 "
0ebbfa1339c67b716f4ac8123a892d85962f100fjorton "%d total children", idle_spawn_rate,
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_count, total_non_dead);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe for (i = 0; i < free_length; ++i) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe make_child(server_conf, free_slots[i], now);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* the next time around we want to spawn twice as many if this
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * wasn't good enough, but not if we've just done a graceful
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (hold_off_on_exponential_spawning) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe --hold_off_on_exponential_spawning;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else if (idle_spawn_rate < MAX_SPAWN_RATE) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe idle_spawn_rate *= 2;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe idle_spawn_rate = 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic void process_child_status(int tid, ap_wait_t status)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* Child died... if it died due to a fatal error,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * we should simply bail out.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if ((WIFEXITED(status)) &&
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe WEXITSTATUS(status) == APEXIT_CHILDFATAL) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Child %d returned a Fatal error... \n"
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Apache is exiting!",
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe tid);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe exit(APEXIT_CHILDFATAL);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (WIFSIGNALED(status)) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe switch (WTERMSIG(status)) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe case SIGTERM:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe case SIGHUP:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe case SIGUSR1:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe case SIGKILL:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe break;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe default:
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef SYS_SIGLIST
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#ifdef WCOREDUMP
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (WCOREDUMP(status)) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "child tid %d exit signal %s (%d), "
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "possible coredump in %s",
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe tid, (WTERMSIG(status) >= NumSIG) ? "" :
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status),
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_coredump_dir);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "child tid %d exit signal %s (%d)", tid,
f4c310fd2555c6faca1f980f00b161eadb089023gstein SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status));
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef WCOREDUMP
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "child tid %d exit signal %d",
f4c310fd2555c6faca1f980f00b161eadb089023gstein tid, WTERMSIG(status));
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe/*****************************************************************
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * Executive routines.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wroweint ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int remaining_children_to_start;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int i;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_status_t status;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe pconf = _pconf;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe server_conf = s;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_pid(pconf, ap_pid_fname);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if ((status = ap_listen_open(s->process, s->port)) != APR_SUCCESS) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, status, s,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "no listening sockets available, shutting down");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return -1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein SAFE_ACCEPT(accept_mutex_init(pconf));
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (!is_graceful) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe reinit_scoreboard(pconf);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe set_signals();
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ppthread_globals == NULL) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (DosAllocThreadLocalMemory(1, (PULONG *)&ppthread_globals)) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Error allocating thread local storage"
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Apache is exiting!");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe } else {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe *ppthread_globals = (struct thread_globals *)ap_palloc(pconf, sizeof(struct thread_globals));
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ap_daemons_max_free < ap_daemons_min_free + 1) /* Don't thrash... */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_daemons_max_free = ap_daemons_min_free + 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* If we're doing a graceful_restart then we're going to see a lot
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * of children exiting immediately when we get into the main loop
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * below (because we just sent them SIGUSR1). This happens pretty
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * rapidly... and for each one that exits we'll start a new one until
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * we reach at least daemons_min_free. But we may be permitted to
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * start more than that, so we'll just keep track of how many we're
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * supposed to start up without the 1 second penalty between each fork.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe remaining_children_to_start = ap_daemons_to_start;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (remaining_children_to_start > ap_daemons_limit) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe remaining_children_to_start = ap_daemons_limit;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (!is_graceful) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe startup_children(remaining_children_to_start);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe remaining_children_to_start = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* give the system some time to recover before kicking into
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * exponential mode */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe hold_off_on_exponential_spawning = 10;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "%s configured -- resuming normal operations",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_get_server_version());
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Server built: %s", ap_get_server_built());
f4c310fd2555c6faca1f980f00b161eadb089023gstein restart_pending = shutdown_pending = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!restart_pending && !shutdown_pending) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int child_slot;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_wait_t status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int tid = wait_or_timeout(&status);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: if it takes longer than 1 second for all our children
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to start up and get into IDLE state then we may spawn an
f4c310fd2555c6faca1f980f00b161eadb089023gstein * extra child
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (tid >= 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein process_child_status(tid, status);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* non-fatal death... note that it's gone in the scoreboard. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_slot = find_child_by_tid(tid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (child_slot >= 0) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe (void) ap_update_child_status(child_slot, SERVER_DEAD,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe (request_rec *) NULL);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (remaining_children_to_start
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe && child_slot < ap_daemons_limit) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* we're still doing a 1-for-1 replacement of dead
f4c310fd2555c6faca1f980f00b161eadb089023gstein * children with new children
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein make_child(server_conf, child_slot, time(0));
f4c310fd2555c6faca1f980f00b161eadb089023gstein --remaining_children_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef APR_HAS_OTHER_CHILD
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* TODO: this won't work, we waited on a thread not a process
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (reap_other_child(pid, status) == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Great, we've probably just lost a slot in the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * scoreboard. Somehow we don't know about this
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * child.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, server_conf,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "long lost child came home! (tid %d)", tid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Don't perform idle maintenance when a child dies,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * only do it when there's a timeout. Remember only a
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * finite number of children can die, and it's pretty
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * pathological for a lot to die suddenly.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (remaining_children_to_start) {
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein /* we hit a 1 second timeout in which none of the previous
f4c310fd2555c6faca1f980f00b161eadb089023gstein * generation of children needed to be reaped... so assume
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * they're all done, and pick up the slack if any is left.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein startup_children(remaining_children_to_start);
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein remaining_children_to_start = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* In any event we really shouldn't do the code below because
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * few of the servers we just started are in the IDLE state
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * yet, so we'd mistakenly create an extra server.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein perform_idle_server_maintenance();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (shutdown_pending) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Time to gracefully shut down */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein const char *pidfile = NULL;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein int slot;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe TID tid;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ULONG rc;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (lr = ap_listeners; lr; lr = lr->next) {
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_close_socket(lr->sd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein DosSleep(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Kill off running threads */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (slot=0; slot<max_daemons_limit; slot++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image->servers[slot].status != SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein tid = ap_scoreboard_image->parent[slot].tid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rc = DosKillThread(tid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rc != ERROR_INVALID_THREADID) { // Already dead, ignore
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rc == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rc = DosWaitThread(&tid, DCWW_WAIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rc) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "error %lu waiting for thread to terminate", rc);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz } else {
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, server_conf,
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz "error %lu killing thread", rc);
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz }
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz }
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz }
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* cleanup pid file on normal shutdown */
f4c310fd2555c6faca1f980f00b161eadb089023gstein pidfile = ap_server_root_relative (pconf, ap_pid_fname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ( pidfile != NULL && unlink(pidfile) == 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "removed PID file %s (pid=%ld)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein pidfile, (long)getpid());
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "caught SIGTERM, shutting down");
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we've been told to restart */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGHUP, SIG_IGN);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe signal(SIGUSR1, SIG_IGN);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* not worth thinking about */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* advance to the next generation */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: we really need to make sure this new generation number isn't in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * use by any of the children.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++ap_scoreboard_image->global.running_generation;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "SIGUSR1 received. Doing graceful restart");
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* kill off the idle ones */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe for (i = 0; i < ap_daemons_limit; ++i) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_scoreboard_image->parent[i].deferred_die = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This is mostly for debugging... so that we know what is still
f4c310fd2555c6faca1f980f00b161eadb089023gstein * gracefully dealing with existing request. But we can't really
f4c310fd2555c6faca1f980f00b161eadb089023gstein * do it if we're in a SCOREBOARD_FILE because it'll cause
f4c310fd2555c6faca1f980f00b161eadb089023gstein * corruption too easily.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < ap_daemons_limit; ++i) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ap_scoreboard_image->servers[i].status != SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->servers[i].status = SERVER_GRACEFUL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Kill 'em off */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe for (i = 0; i < ap_daemons_limit; ++i) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe DosKillThread(ap_scoreboard_image->parent[i].tid);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "SIGHUP received. Attempting to restart");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_restart_time = time(NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void spmt_os2_pre_config(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein one_process = !!getenv("ONE_PROCESS");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe is_graceful = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_pre_config();
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_to_start = DEFAULT_START_DAEMON;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_min_free = DEFAULT_MIN_FREE_DAEMON;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_max_free = DEFAULT_MAX_FREE_DAEMON;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_limit = HARD_SERVER_LIMIT;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pid_fname = DEFAULT_PIDLOG;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_extended_status = 0;
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gsteinstatic void spmt_os2_hooks(void)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein INIT_SIGLIST();
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* TODO: set one_process properly */ one_process = 0;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_hook_pre_config(spmt_os2_pre_config, NULL, NULL, AP_HOOK_MIDDLE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic const char *set_pidfile(cmd_parms *cmd, void *dummy, char *arg)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein if (cmd->server->is_virtual) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return "PidFile directive not allowed in <VirtualHost>";
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pid_fname = arg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein ap_daemons_to_start = atoi(arg);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic const char *set_min_free_servers(cmd_parms *cmd, void *dummy, char *arg)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_daemons_min_free = atoi(arg);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ap_daemons_min_free <= 0) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "WARNING: detected MinSpareServers set to non-positive.");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Resetting to 1 to avoid almost certain Apache failure.");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Please read the documentation.");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_daemons_min_free = 1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic const char *set_max_free_servers(cmd_parms *cmd, void *dummy, char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_daemons_max_free = atoi(arg);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic const char *set_server_limit (cmd_parms *cmd, void *dummy, char *arg)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_limit = atoi(arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_daemons_limit > HARD_SERVER_LIMIT) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "WARNING: MaxClients of %d exceeds compile time limit "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "of %d servers,", ap_daemons_limit, HARD_SERVER_LIMIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein " lowering MaxClients to %d. To increase, please "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "see the", HARD_SERVER_LIMIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein " HARD_SERVER_LIMIT define in src/include/httpd.h.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_limit = HARD_SERVER_LIMIT;
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (ap_daemons_limit < 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "WARNING: Require MaxClients > 0, setting to 1");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_daemons_limit = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_max_requests(cmd_parms *cmd, void *dummy, char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_requests_per_child = atoi(arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_coredumpdir (cmd_parms *cmd, void *dummy, char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein struct stat finfo;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *fname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein fname = ap_server_root_relative(cmd->pool, arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((stat(fname, &finfo) == -1) || !S_ISDIR(finfo.st_mode)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname,
f4c310fd2555c6faca1f980f00b161eadb089023gstein " does not exist or is not a directory", NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir));
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Stub functions until this MPM supports the connection status API */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT(void) ap_update_connection_status(long conn_id, const char *key, \
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *value)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOP */
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT(void) ap_reset_connection_status(long conn_id)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOP */
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantzstatic const command_rec spmt_os2_cmds[] = {
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantzLISTEN_COMMANDS
f4c310fd2555c6faca1f980f00b161eadb089023gstein{ "PidFile", set_pidfile, NULL, RSRC_CONF, TAKE1,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "A file for logging the server process ID"},
f4c310fd2555c6faca1f980f00b161eadb089023gstein{ "StartServers", set_daemons_to_start, NULL, RSRC_CONF, TAKE1,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Number of child processes launched at server startup" },
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{ "MinSpareServers", set_min_free_servers, NULL, RSRC_CONF, TAKE1,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Minimum number of idle children, to handle request spikes" },
f4c310fd2555c6faca1f980f00b161eadb089023gstein{ "MaxSpareServers", set_max_free_servers, NULL, RSRC_CONF, TAKE1,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Maximum number of idle children" },
f4c310fd2555c6faca1f980f00b161eadb089023gstein{ "MaxClients", set_server_limit, NULL, RSRC_CONF, TAKE1,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "Maximum number of children alive at the same time" },
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{ "MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, TAKE1,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Maximum number of requests a particular child serves before dying." },
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{ "CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF, TAKE1,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The location of the directory Apache changes to before dumping core" },
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{ NULL }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe};
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowemodule MODULE_VAR_EXPORT mpm_spmt_os2_module = {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe MPM20_MODULE_STUFF,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe NULL, /* hook to run before apache parses args */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe NULL, /* create per-directory config structure */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe NULL, /* merge per-directory config structures */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe NULL, /* create per-server config structure */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe NULL, /* merge per-server config structures */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe spmt_os2_cmds, /* command ap_table_t */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe NULL, /* handlers */
f4c310fd2555c6faca1f980f00b161eadb089023gstein spmt_os2_hooks, /* register_hooks */
f4c310fd2555c6faca1f980f00b161eadb089023gstein};
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe