mpm_netware.c revision c71d98d9fe23826dfc3ee53bbfa39c3f121a839b
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* ====================================================================
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * The Apache Software License, Version 1.1
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * reserved.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Redistribution and use in source and binary forms, with or without
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * modification, are permitted provided that the following conditions
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * are met:
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 1. Redistributions of source code must retain the above copyright
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * notice, this list of conditions and the following disclaimer.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 2. Redistributions in binary form must reproduce the above copyright
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * notice, this list of conditions and the following disclaimer in
27e52281f1522522b170cafc76b08b58aa70ccaand * the documentation and/or other materials provided with the
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * distribution.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 3. The end-user documentation included with the redistribution,
4b5981e276e93df97c34e4da05ca5cf8bbd937dand * if any, must include the following acknowledgment:
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * "This product includes software developed by the
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Apache Software Foundation (http://www.apache.org/)."
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Alternately, this acknowledgment may appear in the software itself,
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * if and wherever such third-party acknowledgments normally appear.
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * 4. The names "Apache" and "Apache Software Foundation" must
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * not be used to endorse or promote products derived from this
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * software without prior written permission. For written
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * permission, please contact apache@apache.org.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 5. Products derived from this software may not be called "Apache",
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * nor may "Apache" appear in their name, without prior written
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * permission of the Apache Software Foundation.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * SUCH DAMAGE.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * ====================================================================
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * This software consists of voluntary contributions made by many
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * individuals on behalf of the Apache Software Foundation. For more
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * information on the Apache Software Foundation, please see
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Portions of this software are based upon public domain software
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * originally written at the National Center for Supercomputing Applications,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * University of Illinois, Urbana-Champaign.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * httpd.c: simple http daemon for answering WWW file requests
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 03-21-93 Rob McCool wrote original code (up to NCSA HTTPd 1.3)
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 03-06-95 blong
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * changed server number for child-alone processes to 0 and changed name
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * of processes
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 03-10-95 blong
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Added numerous speed hacks proposed by Robert S. Thau (rst@ai.mit.edu)
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * including set group before fork, and call gettime before to fork
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * to set up libraries.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * 04-14-95 rst / rh
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Brandon's code snarfed from NCSA 1.4, but tinkered to work with the
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Apache server, and also to have child processes do accept() directly.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * April-July '95 rst
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Extensive rework for Apache.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* Limit on the total --- clients will be locked out if more servers than
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * this are needed. It is intended solely to keep the server from crashing
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * when things get out of hand.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * We keep a hard maximum number of servers, for two reasons --- first off,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * in case something goes seriously wrong, we want to stop the fork bomb
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * short of actually crashing the machine we're running on by filling some
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * kernel table. Secondly, it keeps the size of the scoreboard file small
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * enough that we can read the whole thing without worrying too much about
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * the overhead.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* config globals */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndint ap_threads_per_child=0; /* Worker threads per child */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * The max child slot ever assigned, preserved across restarts. Necessary
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * to deal with MaxClients changes across SIGWINCH restarts. We use this
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * value to optimize routines that have to scan the entire scoreboard.
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* *Non*-shared http_main globals... */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic apr_pool_t *pmain; /* Pool for httpd child stuff */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic pid_t ap_my_pid; /* it seems silly to call getpid all the time */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic int die_now = 0;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* Keep track of the number of worker threads currently active */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* Structure used to register/deregister a console handler with the OS */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic int InstallConsoleHandler(void);
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic void RemoveConsoleHandler(void);
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic int CommandLineInterpreter(scr_t screenID, const char *commandLine);
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic int show_settings = 0;
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd/* a clean exit from a child with proper cleanup */
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndstatic void clean_child_exit(int code, int worker_num) __attribute__ ((noreturn));
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd ap_update_child_status_from_indexes(0, worker_num, WORKER_DEAD,
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bndAP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
9c1260efa52c82c2a58e5b5f20cd6902563d95f5rbowen/*****************************************************************
8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6bnd * Connection structures and accounting...
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
static void mpm_term(void)
wait_to_finish = 0;
while (wait_to_finish) {
static void restart(void)
static void set_signals(void)
int nlmUnloadSignaled()
int ap_graceful_stop_signalled(void)
static int dont_block = 0;
static int missed_accept = 0;
static int skipped_selects = 0;
static int would_block = 0;
int requests_this_child = 0;
int sockdes;
int srv;
while (!die_now) {
if ((ap_max_requests_per_child > 0
if (shutdown_pending || restart_pending || (ap_scoreboard_image->servers[0][my_worker_num].status == WORKER_IDLE_KILL)) {
if (dont_block) {
dont_block = 0;
if (srv <= 0)
if (!lr)
goto got_listener;
if (!lr)
missed_accept = 0;
case WSAEWOULDBLOCK:
would_block++;
case WSAECONNRESET:
case WSAETIMEDOUT:
case WSAEHOSTUNREACH:
case WSAENETUNREACH:
case WSAENETDOWN:
if (current_conn) {
int tid;
int err=0;
if (ctx = NXContextAlloc((void (*)(void *)) worker_main, (void*)slot, NX_PRIO_MED, ap_thread_stack_size, NX_CTX_NORMAL, &err)) {
if (err) {
if (err) {
#ifndef MAX_SPAWN_RATE
static int hold_off_on_exponential_spawning;
int to_kill;
int idle_count;
int free_length;
int last_non_dead;
int total_non_dead;
free_length = 0;
idle_count = 0;
total_non_dead = 0;
for (i = 0; i < ap_threads_limit; ++i) {
int status;
++free_length;
++ idle_count;
to_kill = i;
last_non_dead = i;
if (free_length == 0) {
static int reported = 0;
if (!reported) {
"to increase StartServers, or Min/MaxSpareServers), "
for (i = 0; i < free_length; ++i) {
static void display_settings ()
request_count = 0;
skipped_selects = 0;
would_block = 0;
for (i=0;i<SERVER_NUM_STATUS;i++) {
status_array[i] = 0;
for (i = 0; i < ap_threads_limit; ++i) {
for (i=0;i<SERVER_NUM_STATUS;i++) {
case SERVER_DEAD:
case SERVER_STARTING:
case SERVER_READY:
case SERVER_BUSY_READ:
case SERVER_BUSY_WRITE:
case SERVER_BUSY_KEEPALIVE:
case SERVER_BUSY_LOG:
case SERVER_BUSY_DNS:
case SERVER_CLOSING:
case SERVER_GRACEFUL:
case SERVER_IDLE_KILL:
if (i != SERVER_DEAD)
static void show_server_data()
module **m;
int sockdes;
#ifdef NONBLOCK1
static int shutdown_listeners()
ap_server_conf = s;
if (setup_listeners(s)) {
worker_thread_count = 0;
if (!is_graceful) {
set_signals();
request_count = 0;
if (show_settings)
while (worker_thread_count > 0)
while (worker_thread_count > 0) {
int debug;
is_graceful = 0;
if (addrspace)
ap_extended_status = 0;
return OK;
char *def_server_root;
const char *opt_arg;
for (i=len; i; i--) {
s[i] = NULL;
if (opt_arg) {
char *pID;
return NOTMYCOMMAND;
return NOTMYCOMMAND;
return NOTMYCOMMAND;
return NOTMYCOMMAND;
restart();
if (show_settings) {
show_settings = 0;
show_settings = 0;
return HANDLEDCOMMAND;
return NOTMYCOMMAND;
static int InstallConsoleHandler(void)
static void RemoveConsoleHandler(void)
return err;
return NULL;
return err;
if (ap_threads_min_free <= 0) {
return NULL;
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
return NULL;
{ NULL }