beos.c revision 2571b1566efc927f3cec0be8d0ee9212703a0541
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor/* ====================================================================
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Redistribution and use in source and binary forms, with or without
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * modification, are permitted provided that the following conditions
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * 1. Redistributions of source code must retain the above copyright
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * notice, this list of conditions and the following disclaimer.
2e545ce2450a9953665f701bb05350f0d3f26275nd * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * distribution.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * "This product includes software developed by the
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Apache Software Foundation (http://www.apache.org/)."
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if and wherever such third-party acknowledgments normally appear.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * 4. The names "Apache" and "Apache Software Foundation" must
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * not be used to endorse or promote products derived from this
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * software without prior written permission. For written
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * permission, please contact apache@apache.org.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * 5. Products derived from this software may not be called "Apache",
4a56677aad9b66a36f3dc9fddbca8dc1230ad471rbowen * nor may "Apache" appear in their name, without prior written
4a56677aad9b66a36f3dc9fddbca8dc1230ad471rbowen * permission of the Apache Software Foundation.
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * SUCH DAMAGE.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * ====================================================================
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * This software consists of voluntary contributions made by many
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * individuals on behalf of the Apache Software Foundation. For more
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * information on the Apache Software Foundation, please see
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Portions of this software are based upon public domain software
4aa603e6448b99f9371397d439795c91a93637eand * originally written at the National Center for Supercomputing Applications,
727872d18412fc021f03969b8641810d8896820bhumbedooh * University of Illinois, Urbana-Champaign.
727872d18412fc021f03969b8641810d8896820bhumbedooh/* The new BeOS MPM!
727872d18412fc021f03969b8641810d8896820bhumbedooh * This one basically is a single process multi threaded model, but
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * I couldn't be bothered adding the spmt_ to the front of the name!
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * Anyway, this is still under development so it isn't yet the default
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * Actual definitions of config globals
3c13a815670b54d1c17bf02954f7d2b066cde95cndint ap_threads_per_child=0; /* Worker threads per child */
727872d18412fc021f03969b8641810d8896820bhumbedoohstatic int num_listening_sockets = 0; /* set by open_listeners in ap_mpm_run */
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic apr_pool_t *pchild; /* Pool for httpd child stuff */
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic/* Keep track of the number of worker threads currently active */
727872d18412fc021f03969b8641810d8896820bhumbedooh/* The structure used to pass unique initialization info to each thread */
727872d18412fc021f03969b8641810d8896820bhumbedoohtypedef struct {
727872d18412fc021f03969b8641810d8896820bhumbedoohstruct ap_ctable ap_child_table[HARD_SERVER_LIMIT];
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic * The max child slot ever assigned, preserved across restarts. Necessary
cd8142d105a47b208d863bea7cdb540727a5f02digalic * to deal with MaxClients changes across SIGWINCH restarts. We use this
cd8142d105a47b208d863bea7cdb540727a5f02digalic * value to optimize routines that have to scan the entire scoreboard.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic volatile bool flag_of_death;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor/* shared http_main globals... */
cd8142d105a47b208d863bea7cdb540727a5f02digalic/* one_process */
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic int one_process = 0;
3c13a815670b54d1c17bf02954f7d2b066cde95cnd/* a clean exit from a child with proper cleanup
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor static void clean_child_exit(int code) __attribute__ ((noreturn)); */
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor/* handle all varieties of core dumping signals */
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor /* At this point we've got sig blocked, because we're still inside
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * the signal handler. When we leave the signal handler it will
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * be unblocked, and we'll take the signal... and coredump or whatever
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * is appropriate for this particular Unix. In addition the parent
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * will see the real signal we received -- whereas if we called
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * abort() here, the parent would only see SIGABRT.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor/*****************************************************************
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Connection structures and accounting...
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor/* volatile just in case */
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic int volatile shutdown_pending;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic int volatile restart_pending;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic int volatile is_graceful;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * ap_start_shutdown() and ap_start_restart(), below, are a first stab at
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * functions to initiate shutdown or restart without relying on signals.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Previously this was initiated in sig_term() and restart() signal handlers,
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * but we want to be able to start a shutdown/restart from other sources --
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * e.g. on Win32, from the service manager. Now the service manager can
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * call ap_start_shutdown() or ap_start_restart() as appropiate. Note that
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * these functions can also be called by the child processes, since global
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * variables are no longer used to pass on the required action to the parent.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * These should only be called from the parent process itself, since the
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * parent process will use the shutdown_pending and restart_pending variables
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * to determine whether to shutdown or restart. The child process should
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * call signal_parent() directly to tell the parent to die -- this will
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * cause neither of those variable to be set, which the parent will
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * assume means something serious is wrong (which it will be, for the
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * child to force an exit) and so do an exit anyway.
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic void ap_start_shutdown(void)
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung /* Um, is this _probably_ not an error, if the user has
727872d18412fc021f03969b8641810d8896820bhumbedooh * tried to do a shutdown twice quickly, so we won't
0d0ba3a410038e179b695446bb149cce6264e0abnd * worry about reporting it.
0d0ba3a410038e179b695446bb149cce6264e0abnd/* do a graceful restart if graceful == 1 */
0d0ba3a410038e179b695446bb149cce6264e0abnd /* Probably not an error - don't bother reporting it */
static void tell_workers_to_exit(void)
flag_of_death = true;
for (i=0;i<ap_max_child_assigned;i++)
static void set_signals(void)
if (!one_process) {
int ap_graceful_stop_signalled(void)
return is_graceful;
int csd;
if (current_conn) {
int srv , n;
int this_worker_should_exit = 0;
for(n=0 ; n < num_listening_sockets ; ++n)
while (!this_worker_should_exit) {
if (this_worker_should_exit) break;
while (!this_worker_should_exit) {
if (flag_of_death)
if (this_worker_should_exit) break;
goto got_fd;
curr_pollfd++;
goto got_fd;
if (!this_worker_should_exit) {
if (worker_thread_count == 0) {
if (one_process) {
set_signals();
my_info);
#ifndef MAX_SPAWN_RATE
static int hold_off_on_exponential_spawning;
static void perform_idle_server_maintenance(void)
int free_length;
int last_non_dead;
free_length = 0;
for (i = 0; i < ap_thread_limit; ++i) {
++free_length;
last_non_dead = i;
if (free_length > 0) {
for (i = 0; i < free_length; ++i) {
int child_slot;
for (i = 0; i < ap_max_child_assigned; ++i) {
child_slot = i;
for (j = 0; j < HARD_THREAD_LIMIT; j++) {
if (child_slot >= 0) {
else if (is_graceful) {
else if (remaining_threads_to_start) {
int remaining_threads_to_start, i;
ap_server_conf = s;
flag_of_death = false;
if (!is_graceful)
set_signals();
/* we assume all goes OK...hmm might want to check that! */
if (!is_graceful) {
if (shutdown_pending) {
0, ap_server_conf,
if (one_process) {
if (is_graceful) {
static int restart_num = 0;
int no_detach = 0;
is_graceful = 0;
one_process = 0;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
if (min_spare_threads <= 0) {
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
const char *fname;
return err;
return NULL;
{ NULL }