mpmt_pthread.c revision be3223a6a18d9a3a3cf7155d5430a5d92bcddcee
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna/* ====================================================================
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * The Apache Software License, Version 1.1
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Copyright (c) 2000 The Apache Software Foundation. All rights
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * reserved.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Redistribution and use in source and binary forms, with or without
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * modification, are permitted provided that the following conditions
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * 1. Redistributions of source code must retain the above copyright
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * notice, this list of conditions and the following disclaimer.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * 2. Redistributions in binary form must reproduce the above copyright
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * notice, this list of conditions and the following disclaimer in
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * the documentation and/or other materials provided with the
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * distribution.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * 3. The end-user documentation included with the redistribution,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * if any, must include the following acknowledgment:
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * "This product includes software developed by the
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Apache Software Foundation (http://www.apache.org/)."
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Alternately, this acknowledgment may appear in the software itself,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * if and wherever such third-party acknowledgments normally appear.
5660534a0c83c16ca89cf5aa970b6668d44723fcfuankg * 4. The names "Apache" and "Apache Software Foundation" must
82d8a5c340e2d50ebadc542a6422bacf3c244432pquerna * not be used to endorse or promote products derived from this
5660534a0c83c16ca89cf5aa970b6668d44723fcfuankg * software without prior written permission. For written
047cb8df15a408e0c0c6125c4a351b35aa3c6e82sf * permission, please contact apache@apache.org.
82d8a5c340e2d50ebadc542a6422bacf3c244432pquerna * 5. Products derived from this software may not be called "Apache",
82d8a5c340e2d50ebadc542a6422bacf3c244432pquerna * nor may "Apache" appear in their name, without prior written
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * permission of the Apache Software Foundation.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * SUCH DAMAGE.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * ====================================================================
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * This software consists of voluntary contributions made by many
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * individuals on behalf of the Apache Software Foundation. For more
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * information on the Apache Software Foundation, please see
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Portions of this software are based upon public domain software
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * originally written at the National Center for Supercomputing Applications,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * University of Illinois, Urbana-Champaign.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Actual definitions of config globals
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquernaint ap_threads_per_child=0; /* Worker threads per child */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquernastatic int workers_may_exit = 0;
static int requests_this_child;
static int num_listensocks = 0;
int pid;
int tid;
int sd;
} proc_info;
static int one_process = 0;
#ifdef DEBUG_SIGSTOP
int raise_sigstop_flags;
static int worker_thread_count;
static const char *lock_fname;
#ifdef NO_SERIALIZED_ACCEPT
return ap_max_daemons_limit;
if (pchild) {
clean_child_exit(0);
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
static void ap_start_shutdown(void)
if (is_graceful) {
#ifndef WIN32
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 SIGWINCH
#ifdef SIGPIPE
int ap_graceful_stop_signalled(void)
return is_graceful;
int csd;
if (current_conn) {
static void check_pipe_of_death(void)
if (!workers_may_exit) {
char pipe_read_char;
for(n=0 ; n <= num_listensocks ; ++n)
if (workers_may_exit) break;
!= APR_SUCCESS) {
while (!workers_may_exit) {
if (workers_may_exit) break;
goto got_fd;
curr_pollfd++;
goto got_fd;
if (!workers_may_exit) {
!= APR_SUCCESS) {
!= APR_SUCCESS) {
if (worker_thread_count == 0) {
return NULL;
int signal_received;
pchild));
if (unixd_setup_child()) {
#ifdef SIGPROCMASK_SETS_THREAD_MASK
#ifdef PTHREAD_SETS_ERRNO
worker_thread_count = 0;
for (i=0; i < ap_threads_per_child; i++) {
#ifndef NO_THREADS
#ifdef PTHREAD_SETS_ERRNO
switch (signal_received) {
case SIGTERM:
case SIGINT:
int pid;
if (one_process) {
set_signals();
if (!pid) {
#ifdef AIX_BIND_PROCESSOR
#ifndef MAX_SPAWN_RATE
static int hold_off_on_exponential_spawning;
static void perform_idle_server_maintenance(void)
int idle_thread_count;
int free_length;
int last_non_dead;
int total_non_dead;
free_length = 0;
idle_thread_count = 0;
total_non_dead = 0;
for (i = 0; i < ap_daemons_limit; ++i) {
int any_dying_threads = 0;
int idle_thread_addition = 0;
for (j = 0; j < ap_threads_per_child; j++) {
++free_length;
if (!all_dead_threads) {
last_non_dead = i;
if (!any_dying_threads) {
if (free_length == 0) {
static int reported = 0;
if (!reported) {
"or Min/MaxSpareThreads), "
for (i = 0; i < free_length; ++i) {
int child_slot;
if (child_slot >= 0) {
for (i = 0; i < ap_threads_per_child; i++)
else if (is_graceful) {
else if (remaining_children_to_start) {
ap_server_conf = s;
ap_server_conf = s;
if (!is_graceful) {
set_signals();
if (!is_graceful) {
if (shutdown_pending) {
if (one_process) {
if (is_graceful) {
for (i = 0; i < ap_daemons_limit;) {
for (i = 0; i < ap_daemons_limit; ++i) {
for (j = 0; j < ap_threads_per_child; j++) {
static int restart_num = 0;
int no_detach = 0;
is_graceful = 0;
ap_extended_status = 0;
one_process = 0;
return err;
return NULL;
const char *arg)
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
if (min_spare_threads <= 0) {
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "WARNING: Require MaxClients > 0, setting to 1");
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
const char *fname;
return err;
return NULL;
{ NULL }