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