beos.c revision 26dfa083a1662d57ba7cc410eec4e0696b9be469
e609c337f729875bc20e01096c7e610f45356f54nilgun/* ====================================================================
e609c337f729875bc20e01096c7e610f45356f54nilgun * The Apache Software License, Version 1.1
e609c337f729875bc20e01096c7e610f45356f54nilgun * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
e609c337f729875bc20e01096c7e610f45356f54nilgun * reserved.
e609c337f729875bc20e01096c7e610f45356f54nilgun * Redistribution and use in source and binary forms, with or without
e609c337f729875bc20e01096c7e610f45356f54nilgun * modification, are permitted provided that the following conditions
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 2. Redistributions in binary form must reproduce the above copyright
e609c337f729875bc20e01096c7e610f45356f54nilgun * notice, this list of conditions and the following disclaimer in
e609c337f729875bc20e01096c7e610f45356f54nilgun * the documentation and/or other materials provided with the
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen * distribution.
e609c337f729875bc20e01096c7e610f45356f54nilgun * 3. The end-user documentation included with the redistribution,
e609c337f729875bc20e01096c7e610f45356f54nilgun * if any, must include the following acknowledgment:
e609c337f729875bc20e01096c7e610f45356f54nilgun * "This product includes software developed by the
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * Apache Software Foundation (http://www.apache.org/)."
e609c337f729875bc20e01096c7e610f45356f54nilgun * Alternately, this acknowledgment may appear in the software itself,
e609c337f729875bc20e01096c7e610f45356f54nilgun * if and wherever such third-party acknowledgments normally appear.
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * 4. The names "Apache" and "Apache Software Foundation" must
e609c337f729875bc20e01096c7e610f45356f54nilgun * not be used to endorse or promote products derived from this
e8897b2f72c5fc3bf4a5da96745a320a8b2acae7rbowen * software without prior written permission. For written
e609c337f729875bc20e01096c7e610f45356f54nilgun * permission, please contact apache@apache.org.
e609c337f729875bc20e01096c7e610f45356f54nilgun * 5. Products derived from this software may not be called "Apache",
e609c337f729875bc20e01096c7e610f45356f54nilgun * nor may "Apache" appear in their name, without prior written
e609c337f729875bc20e01096c7e610f45356f54nilgun * permission of the Apache Software Foundation.
e609c337f729875bc20e01096c7e610f45356f54nilgun * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
e609c337f729875bc20e01096c7e610f45356f54nilgun * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
e609c337f729875bc20e01096c7e610f45356f54nilgun * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e609c337f729875bc20e01096c7e610f45356f54nilgun * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e609c337f729875bc20e01096c7e610f45356f54nilgun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
e609c337f729875bc20e01096c7e610f45356f54nilgun * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
e609c337f729875bc20e01096c7e610f45356f54nilgun * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
e609c337f729875bc20e01096c7e610f45356f54nilgun * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
e609c337f729875bc20e01096c7e610f45356f54nilgun * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e609c337f729875bc20e01096c7e610f45356f54nilgun * SUCH DAMAGE.
e609c337f729875bc20e01096c7e610f45356f54nilgun * ====================================================================
e609c337f729875bc20e01096c7e610f45356f54nilgun * This software consists of voluntary contributions made by many
e609c337f729875bc20e01096c7e610f45356f54nilgun * individuals on behalf of the Apache Software Foundation. For more
e609c337f729875bc20e01096c7e610f45356f54nilgun * information on the Apache Software Foundation, please see
e609c337f729875bc20e01096c7e610f45356f54nilgun * Portions of this software are based upon public domain software
e609c337f729875bc20e01096c7e610f45356f54nilgun * originally written at the National Center for Supercomputing Applications,
e609c337f729875bc20e01096c7e610f45356f54nilgun * University of Illinois, Urbana-Champaign.
e609c337f729875bc20e01096c7e610f45356f54nilgun/* The new BeOS MPM!
e609c337f729875bc20e01096c7e610f45356f54nilgun * This one basically is a single process multi threaded model, but
e609c337f729875bc20e01096c7e610f45356f54nilgun * I couldn't be bothered adding the spmt_ to the front of the name!
e609c337f729875bc20e01096c7e610f45356f54nilgun * Anyway, this is still under development so it isn't yet the default
e609c337f729875bc20e01096c7e610f45356f54nilgun/* Limit on the total --- clients will be locked out if more servers than
e609c337f729875bc20e01096c7e610f45356f54nilgun * this are needed. It is intended solely to keep the server from crashing
e609c337f729875bc20e01096c7e610f45356f54nilgun * when things get out of hand.
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun * We keep a hard maximum number of servers, for two reasons:
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun * 1) in case something goes seriously wrong, we want to stop the server starting
e609c337f729875bc20e01096c7e610f45356f54nilgun * threads ad infinitum and crashing the server (remember that BeOS has a 192
e609c337f729875bc20e01096c7e610f45356f54nilgun * thread per team limit).
e609c337f729875bc20e01096c7e610f45356f54nilgun * 2) it keeps the size of the scoreboard file small
e609c337f729875bc20e01096c7e610f45356f54nilgun * enough that we can read the whole thing without worrying too much about
e609c337f729875bc20e01096c7e610f45356f54nilgun * the overhead.
e609c337f729875bc20e01096c7e610f45356f54nilgun/* we only ever have 1 main process running... */
e609c337f729875bc20e01096c7e610f45356f54nilgun/* Limit on the threads per process. Clients will be locked out if more than
e609c337f729875bc20e01096c7e610f45356f54nilgun * this * HARD_SERVER_LIMIT are needed.
e609c337f729875bc20e01096c7e610f45356f54nilgun * We keep this for one reason it keeps the size of the scoreboard file small
e609c337f729875bc20e01096c7e610f45356f54nilgun * enough that we can read the whole thing without worrying too much about
e609c337f729875bc20e01096c7e610f45356f54nilgun * the overhead.
e609c337f729875bc20e01096c7e610f45356f54nilgun * Actual definitions of config globals
e609c337f729875bc20e01096c7e610f45356f54nilgunstatic apr_pool_t *pchild; /* Pool for httpd child stuff */
e609c337f729875bc20e01096c7e610f45356f54nilgun/* Keep track of the number of worker threads currently active */
e609c337f729875bc20e01096c7e610f45356f54nilgun/* The structure used to pass unique initialization info to each thread */
e609c337f729875bc20e01096c7e610f45356f54nilguntypedef struct {
e609c337f729875bc20e01096c7e610f45356f54nilgun * The max child slot ever assigned, preserved across restarts. Necessary
e609c337f729875bc20e01096c7e610f45356f54nilgun * to deal with MaxClients changes across AP_SIG_GRACEFUL restarts. We use
e609c337f729875bc20e01096c7e610f45356f54nilgun * this value to optimize routines that have to scan the entire scoreboard.
e609c337f729875bc20e01096c7e610f45356f54nilgun/* shared http_main globals... */
e609c337f729875bc20e01096c7e610f45356f54nilgun/* one_process */
e609c337f729875bc20e01096c7e610f45356f54nilgunstatic int one_process = 0;
e609c337f729875bc20e01096c7e610f45356f54nilgun/* a clean exit from a child with proper cleanup
e609c337f729875bc20e01096c7e610f45356f54nilgun static void clean_child_exit(int code) __attribute__ ((noreturn)); */
e609c337f729875bc20e01096c7e610f45356f54nilgun/* handle all varieties of core dumping signals */
e609c337f729875bc20e01096c7e610f45356f54nilgun /* At this point we've got sig blocked, because we're still inside
e609c337f729875bc20e01096c7e610f45356f54nilgun * the signal handler. When we leave the signal handler it will
e609c337f729875bc20e01096c7e610f45356f54nilgun * be unblocked, and we'll take the signal... and coredump or whatever
91f378b5a10f2d83820902ed10ba7967a3920c18nilgun * is appropriate for this particular Unix. In addition the parent
e609c337f729875bc20e01096c7e610f45356f54nilgun * will see the real signal we received -- whereas if we called
e609c337f729875bc20e01096c7e610f45356f54nilgun * abort() here, the parent would only see SIGABRT.
e609c337f729875bc20e01096c7e610f45356f54nilgun/*****************************************************************
e609c337f729875bc20e01096c7e610f45356f54nilgun * Connection structures and accounting...
91f378b5a10f2d83820902ed10ba7967a3920c18nilgun/* volatile just in case */
91f378b5a10f2d83820902ed10ba7967a3920c18nilgunstatic int volatile shutdown_pending;
91f378b5a10f2d83820902ed10ba7967a3920c18nilgunstatic int volatile restart_pending;
91f378b5a10f2d83820902ed10ba7967a3920c18nilgunstatic int volatile is_graceful;
e609c337f729875bc20e01096c7e610f45356f54nilgunstatic int volatile child_fatal;
e609c337f729875bc20e01096c7e610f45356f54nilgun * ap_start_shutdown() and ap_start_restart(), below, are a first stab at
e609c337f729875bc20e01096c7e610f45356f54nilgun * functions to initiate shutdown or restart without relying on signals.
e609c337f729875bc20e01096c7e610f45356f54nilgun * Previously this was initiated in sig_term() and restart() signal handlers,
e609c337f729875bc20e01096c7e610f45356f54nilgun * but we want to be able to start a shutdown/restart from other sources --
e609c337f729875bc20e01096c7e610f45356f54nilgun * e.g. on Win32, from the service manager. Now the service manager can
e609c337f729875bc20e01096c7e610f45356f54nilgun * call ap_start_shutdown() or ap_start_restart() as appropiate. Note that
e609c337f729875bc20e01096c7e610f45356f54nilgun * these functions can also be called by the child processes, since global
e609c337f729875bc20e01096c7e610f45356f54nilgun * variables are no longer used to pass on the required action to the parent.
e609c337f729875bc20e01096c7e610f45356f54nilgun * These should only be called from the parent process itself, since the
e609c337f729875bc20e01096c7e610f45356f54nilgun * parent process will use the shutdown_pending and restart_pending variables
e609c337f729875bc20e01096c7e610f45356f54nilgun * to determine whether to shutdown or restart. The child process should
e609c337f729875bc20e01096c7e610f45356f54nilgun * call signal_parent() directly to tell the parent to die -- this will
e609c337f729875bc20e01096c7e610f45356f54nilgun * cause neither of those variable to be set, which the parent will
e609c337f729875bc20e01096c7e610f45356f54nilgun * assume means something serious is wrong (which it will be, for the
e609c337f729875bc20e01096c7e610f45356f54nilgun * child to force an exit) and so do an exit anyway.
e609c337f729875bc20e01096c7e610f45356f54nilgunstatic void ap_start_shutdown(void)
e609c337f729875bc20e01096c7e610f45356f54nilgun /* Um, is this _probably_ not an error, if the user has
e609c337f729875bc20e01096c7e610f45356f54nilgun * tried to do a shutdown twice quickly, so we won't
e609c337f729875bc20e01096c7e610f45356f54nilgun * worry about reporting it.
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun/* do a graceful restart if graceful == 1 */
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun /* Probably not an error - don't bother reporting it */
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun apr_pool_cleanup_kill(pconf, NULL, ap_cleanup_scoreboard);
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgunstatic void tell_workers_to_exit(void)
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun for (i = 0 ; i < ap_max_child_assigned; i++){
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun if (apr_sendto(udp_sock, udp_sa, 0, "die!", &len) != APR_SUCCESS)
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgunstatic void set_signals(void)
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGSEGV)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGBUS)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABRT)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGILL)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun /* we want to ignore HUPs and AP_SIG_GRACEFUL while we're busy
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun * processing one */
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(" AP_SIG_GRACEFUL_STRING ")");
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun/*****************************************************************
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun * Here follows a long bunch of generic server bookkeeping stuff...
e609c337f729875bc20e01096c7e610f45356f54nilgun /* XXX - Does this really work? - Manoj */
e609c337f729875bc20e01096c7e610f45356f54nilgun/*****************************************************************
e609c337f729875bc20e01096c7e610f45356f54nilgun * Child process main loop.
e609c337f729875bc20e01096c7e610f45356f54nilgunstatic void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num)
727872d18412fc021f03969b8641810d8896820bhumbedooh ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, NULL,
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh "filedescriptor (%u) larger than FD_SETSIZE (%u) "
0d0ba3a410038e179b695446bb149cce6264e0abnd "found, you probably need to rebuild Apache with a "
0d0ba3a410038e179b695446bb149cce6264e0abnd current_conn = ap_run_create_connection(p, ap_server_conf, sock, conn_id, sbh);
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);
if (make_worker(i) < 0) {
#ifndef MAX_SPAWN_RATE
static int hold_off_on_exponential_spawning;
static void perform_idle_server_maintenance(void)
int free_length;
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;
int status;
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_DAEMON_USED:
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;
*result = 0;
return APR_SUCCESS;
return APR_SUCCESS;
*result = 0;
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
case AP_MPMQ_MAX_DAEMONS:
return APR_SUCCESS;
return APR_ENOTIMPL;
int remaining_threads_to_start, i,j;
ap_server_conf = s;
!= APR_SUCCESS){
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 (!one_process) {
(long)getpid());
if (one_process) {
if (shutdown_pending) {
if (is_graceful) {
static int restart_num = 0;
if (debug)
is_graceful = 0;
one_process = 0;
return err;
if (ap_threads_to_start < 0) {
return NULL;
return err;
if (min_spare_threads <= 0) {
return NULL;
return err;
return NULL;
return err;
" HARD_THREAD_LIMIT define in server/mpm/beos/mpm_default.h.");
return NULL;
return err;
if (ap_max_requests_per_thread < 0) {
return NULL;
{ NULL }