spmt_os2.c revision 64185f9824e42f21ca7b9ae6c004484215c031a7
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 1995-2000 The Apache Software Foundation. All rights reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding * Redistribution and use in source and binary forms, with or without
842ae4bd224140319ae7feec1872b93dfd491143fielding * modification, are permitted provided that the following conditions
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * notice, this list of conditions and the following disclaimer.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 2. Redistributions in binary form must reproduce the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer in
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * the documentation and/or other materials provided with the
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distribution.
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * 3. All advertising materials mentioning features or use of this
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * software must display the following acknowledgment:
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * "This product includes software developed by the Apache Software Foundation
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * for use in the Apache HTTP server project (http://www.apache.org/)."
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * 4. The names "Apache Server" and "Apache Software Foundation" must not be used to
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * endorse or promote products derived from this software without
76d43ecb1fce88453844591c37f1ca32e96902e3jwoolley * prior written permission. For written permission, please contact
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * apache@apache.org.
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * 5. Products derived from this software may not be called "Apache"
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * nor may "Apache" appear in their names without prior written
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * permission of the Apache Software Foundation.
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * 6. Redistributions of any form whatsoever must retain the following
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * acknowledgment:
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * "This product includes software developed by the Apache Software Foundation
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * for use in the Apache HTTP server project (http://www.apache.org/)."
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * THIS SOFTWARE IS PROVIDED BY THE Apache Software Foundation ``AS IS'' AND ANY
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE Apache Software Foundation OR
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * OF THE POSSIBILITY OF SUCH DAMAGE.
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * ====================================================================
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * This software consists of voluntary contributions made by many
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * individuals on behalf of the Apache Software Foundation and was originally based
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * on public domain software written at the National Center for
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * Supercomputing Applications, University of Illinois, Urbana-Champaign.
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * For more information on the Apache Software Foundation and the Apache HTTP server
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * project, please see <http://www.apache.org/>.
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz/* config globals */
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * The max child slot ever assigned, preserved across restarts. Necessary
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf * to deal with MaxClients changes across SIGUSR1 restarts. We use this
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz * value to optimize routines that have to scan the entire scoreboard.
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz/* *Non*-shared http_main globals... */
static int one_process = 0;
#ifdef HAS_OTHER_CHILD
struct other_child_rec {
int pid;
void *data;
int write_fd;
struct thread_globals {
int child_num;
int usr1_just_die;
void cleanup_scoreboard(void)
_endthread();
return APR_SUCCESS;
if (rc != 0) {
if (rc != 0) {
static void accept_mutex_on(void)
if (rc != 0) {
static void accept_mutex_off(void)
if (rc != 0) {
#ifdef HAS_OTHER_CHILD
static void probe_writable_fds(void)
int fd_max;
int rc;
fd_max = 0;
if (fd_max == 0)
if (rc == 0)
int old_status;
if (child_num < 0)
if (ap_extended_status) {
return old_status;
if (child_num < 0)
#if !defined(HAVE_GETTIMEOFDAY)
#ifdef HAVE_TIMES
#if !defined(HAVE_GETTIMEOFDAY)
#ifdef HAVE_TIMES
long int bs = 0;
if (r->sent_bodyct)
#ifdef HAVE_TIMES
for (i = 0; i < max_daemons_limit; ++i)
#ifndef INTERVAL_OF_WRITABLE_PROBES
static int wait_or_timeout_counter;
int ret;
#ifdef HAS_OTHER_CHILD
tid = 0;
if (ret == 0) {
return tid;
#if defined(NSIG)
static void siglist_init(void)
int sig;
#ifdef SIGHUP
#ifdef SIGINT
#ifdef SIGQUIT
#ifdef SIGILL
#ifdef SIGTRAP
#ifdef SIGIOT
#ifdef SIGABRT
#ifdef SIGEMT
#ifdef SIGFPE
#ifdef SIGKILL
#ifdef SIGBUS
#ifdef SIGSEGV
#ifdef SIGSYS
#ifdef SIGPIPE
#ifdef SIGALRM
#ifdef SIGTERM
#ifdef SIGUSR1
#ifdef SIGUSR2
#ifdef SIGCLD
#ifdef SIGCHLD
#ifdef SIGPWR
#ifdef SIGWINCH
#ifdef SIGURG
#ifdef SIGPOLL
#ifdef SIGIO
#ifdef SIGSTOP
#ifdef SIGTSTP
#ifdef SIGCONT
#ifdef SIGTTIN
#ifdef SIGTTOU
#ifdef SIGVTALRM
#ifdef SIGPROF
#ifdef SIGXCPU
#ifdef SIGXFSZ
clean_child_exit(0);
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
static void set_signals(void)
#ifndef NO_USE_SIGACTION
if (!one_process) {
#if defined(SA_ONESHOT)
#ifdef SIGBUS
#ifdef SIGABORT
#ifdef SIGABRT
#ifdef SIGILL
#ifdef SIGINT
#ifdef SIGXCPU
#ifdef SIGXFSZ
#ifdef SIGPIPE
if (!one_process) {
#ifdef SIGBUS
#ifdef SIGABORT
#ifdef SIGABRT
#ifdef SIGILL
#ifdef SIGXCPU
#ifdef SIGXFSZ
#ifdef SIGHUP
#ifdef SIGUSR1
#ifdef SIGPIPE
int ap_graceful_stop_signalled(void)
ap_scoreboard_image->global.running_generation != ap_scoreboard_image->parent[THREAD_GLOBAL(child_num)].generation) {
int numfds = 0;
numfds++;
int requests_this_child = 0;
while (!ap_graceful_stop_signalled()) {
int srv;
if ((ap_max_requests_per_child > 0
clean_child_exit(0);
if (srv <= 0)
if (!lr) {
clean_child_exit(0);
switch (rv) {
#ifdef EPROTO
case EPROTO:
#ifdef ECONNABORTED
case ECONNABORTED:
#ifdef ECONNRESET
case ECONNRESET:
#ifdef ETIMEDOUT
case ETIMEDOUT:
#ifdef EHOSTUNREACH
case EHOSTUNREACH:
#ifdef ENETUNREACH
case ENETUNREACH:
if (ap_graceful_stop_signalled()) {
clean_child_exit(0);
clean_child_exit(0);
if (one_process) {
#ifdef SIGQUIT
ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s, "_beginthread: Unable to create new thread");
#ifndef MAX_SPAWN_RATE
static int hold_off_on_exponential_spawning;
static void perform_idle_server_maintenance(void)
int to_kill;
int idle_count;
int free_length;
int last_non_dead;
int total_non_dead;
free_length = 0;
idle_count = 0;
total_non_dead = 0;
for (i = 0; i < ap_daemons_limit; ++i) {
int status;
++free_length;
++ idle_count;
to_kill = i;
last_non_dead = i;
if (free_length == 0) {
static int reported = 0;
if (!reported) {
"to increase StartServers, or Min/MaxSpareServers), "
for (i = 0; i < free_length; ++i) {
tid);
case SIGTERM:
case SIGHUP:
case SIGUSR1:
case SIGKILL:
#ifdef SYS_SIGLIST
#ifdef WCOREDUMP
#ifdef WCOREDUMP
server_conf = s;
if (!is_graceful) {
set_signals();
if (!is_graceful) {
int child_slot;
if (tid >= 0) {
if (child_slot >= 0) {
#ifdef HAS_OTHER_CHILD
else if (is_graceful) {
else if (remaining_children_to_start) {
if (shutdown_pending) {
int slot;
if (rc == 0) {
if (rc) {
if (one_process) {
if (is_graceful) {
for (i = 0; i < ap_daemons_limit; ++i) {
for (i = 0; i < ap_daemons_limit; ++i) {
for (i = 0; i < ap_daemons_limit; ++i) {
if (!is_graceful) {
is_graceful = 0;
ap_extended_status = 0;
static void spmt_os2_hooks(void)
INIT_SIGLIST();
return err;
return NULL;
return err;
return NULL;
return err;
if (ap_daemons_min_free <= 0) {
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
const char *fname;
return err;
return NULL;
const char *value)
{ NULL }