mpmt_pthread.c revision a1de70bda57b72d8cc6b47ea744e0973ed424f56
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
2d2eda71267231c2526be701fe655db125852c1ffielding * Redistribution and use in source and binary forms, with or without
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * modification, are permitted provided that the following conditions
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 2. Redistributions in binary form must reproduce the above copyright
2d2eda71267231c2526be701fe655db125852c1ffielding * notice, this list of conditions and the following disclaimer in
2d2eda71267231c2526be701fe655db125852c1ffielding * the documentation and/or other materials provided with the
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * distribution.
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * 3. The end-user documentation included with the redistribution,
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * if any, must include the following acknowledgment:
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * "This product includes software developed by the
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * Apache Software Foundation (http://www.apache.org/)."
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * Alternately, this acknowledgment may appear in the software itself,
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * if and wherever such third-party acknowledgments normally appear.
2d2eda71267231c2526be701fe655db125852c1ffielding * 4. The names "Apache" and "Apache Software Foundation" must
2d2eda71267231c2526be701fe655db125852c1ffielding * not be used to endorse or promote products derived from this
2d2eda71267231c2526be701fe655db125852c1ffielding * software without prior written permission. For written
2d2eda71267231c2526be701fe655db125852c1ffielding * permission, please contact apache@apache.org.
2d2eda71267231c2526be701fe655db125852c1ffielding * 5. Products derived from this software may not be called "Apache",
2d2eda71267231c2526be701fe655db125852c1ffielding * nor may "Apache" appear in their name, without prior written
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * permission of the Apache Software Foundation.
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45acd673a68181802b112e97e84fa3813ddd3ec1stoddard * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2d2eda71267231c2526be701fe655db125852c1ffielding * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
742318b93e89c311f66b55f426c4d9cf2c14628bjim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ebc18d48bea83ee5ed7a1b4e30007e5192539829wrowe * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2d2eda71267231c2526be701fe655db125852c1ffielding * SUCH DAMAGE.
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * ====================================================================
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * This software consists of voluntary contributions made by many
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * individuals on behalf of the Apache Software Foundation. For more
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * information on the Apache Software Foundation, please see
2d2eda71267231c2526be701fe655db125852c1ffielding * Portions of this software are based upon public domain software
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * originally written at the National Center for Supercomputing Applications,
742318b93e89c311f66b55f426c4d9cf2c14628bjim * University of Illinois, Urbana-Champaign.
d2227b43aaee9a78350dc107bdc404859ad1f938rbb * Actual definitions of config globals
d2227b43aaee9a78350dc107bdc404859ad1f938rbbint ap_threads_per_child=0; /* Worker threads per child */
d2227b43aaee9a78350dc107bdc404859ad1f938rbbstatic int workers_may_exit = 0;
d2227b43aaee9a78350dc107bdc404859ad1f938rbbstatic int num_listensocks = 0;
2d2eda71267231c2526be701fe655db125852c1ffielding/* The structure used to pass unique initialization info to each thread */
3d96ee83babeec32482c9082c9426340cee8c44dwrowetypedef struct {
2d2eda71267231c2526be701fe655db125852c1ffielding ap_pool_t *tpool; /* "pthread" would be confusing */
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * The max child slot ever assigned, preserved across restarts. Necessary
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;
void ap_start_shutdown(void)
#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;
conn_id);
static void check_pipe_of_death(void)
if (!workers_may_exit) {
char pipe_read_char;
for(n=0 ; n <= num_listensocks ; ++n)
while (!workers_may_exit) {
if (workers_may_exit) break;
if (workers_may_exit) {
!= 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
worker_thread_count = 0;
for (i=0; i < ap_threads_per_child; i++) {
#ifndef NO_THREADS
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/MaxSparetThreads), "
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++) {
if (!is_graceful) {
static int restart_num = 0;
is_graceful = 0;
if (!one_process) {
ap_detach();
ap_extended_status = 0;
static void mpmt_pthread_hooks(void)
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 }