mpmt_beos.c revision 6f984345bbfa9342dde1f2b7b8c35b7987d078af
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder/* ====================================================================
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * The Apache Software License, Version 1.1
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * Copyright (c) 2000 The Apache Software Foundation. All rights
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * Redistribution and use in source and binary forms, with or without
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * modification, are permitted provided that the following conditions
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * 1. Redistributions of source code must retain the above copyright
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * notice, this list of conditions and the following disclaimer.
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * 2. Redistributions in binary form must reproduce the above copyright
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * notice, this list of conditions and the following disclaimer in
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * the documentation and/or other materials provided with the
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * distribution.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * 3. The end-user documentation included with the redistribution,
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * if any, must include the following acknowledgment:
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * "This product includes software developed by the
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * Apache Software Foundation (http://www.apache.org/)."
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * Alternately, this acknowledgment may appear in the software itself,
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * if and wherever such third-party acknowledgments normally appear.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * 4. The names "Apache" and "Apache Software Foundation" must
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * not be used to endorse or promote products derived from this
79e28be65fd0bc65adf266d5ae4f6deb92546bf7Christian Maeder * software without prior written permission. For written
79e28be65fd0bc65adf266d5ae4f6deb92546bf7Christian Maeder * permission, please contact apache@apache.org.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * 5. Products derived from this software may not be called "Apache",
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * nor may "Apache" appear in their name, without prior written
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * permission of the Apache Software Foundation.
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * SUCH DAMAGE.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * ====================================================================
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * This software consists of voluntary contributions made by many
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * individuals on behalf of the Apache Software Foundation. For more
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * information on the Apache Software Foundation, please see
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * Portions of this software are based upon public domain software
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * originally written at the National Center for Supercomputing Applications,
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * University of Illinois, Urbana-Champaign.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder/* This module is effectivly mpmt_pthread much modified to
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * allow it work on BeOS. It's stable and works OK.
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder#include "http_config.h" /* for read_config */
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder#include "http_core.h" /* for get_remote_host */
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * Actual definitions of config globals
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maederint ap_threads_per_child=0; /* Worker threads per child */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maederstatic apr_pool_t *pconf; /* Pool for config stuff */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maederstatic apr_pool_t *pchild; /* Pool for httpd child stuff */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maederstatic int my_pid; /* Linux getpid() doesn't work except in main thread. Use
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder this instead */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder/* Keep track of the number of worker threads currently active */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder/* The structure used to pass unique initialization info to each thread */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maedertypedef struct {
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder apr_pool_t *tpool; /* "pthread" would be confusing */
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maederstruct ap_ctable ap_child_table[HARD_SERVER_LIMIT];
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * The max child slot ever assigned, preserved across restarts. Necessary
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * to deal with MaxClients changes across SIGWINCH restarts. We use this
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * value to optimize routines that have to scan the entire scoreboard.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder/* shared http_main globals... */
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder/* one_process */
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder/* TODO - get this working again... */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder/* a clean exit from a child with proper cleanup
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder static void clean_child_exit(int code) __attribute__ ((noreturn)); */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder/* handle all varieties of core dumping signals */
clean_child_exit(0);
static int volatile shutdown_pending;
static int volatile restart_pending;
static int volatile is_graceful;
static void ap_start_shutdown(void)
static void set_signals(void)
if (!one_process) {
int ap_graceful_stop_signalled(void)
return is_graceful;
int csd;
int srv;
while (!workers_may_exit) {
if (workers_may_exit) break;
while (!workers_may_exit) {
if (srv < 0) {
if (workers_may_exit) break;
goto got_fd;
curr_pollfd++;
goto got_fd;
if (!workers_may_exit) {
if (worker_thread_count == 0) {
char buf;
if (beosd_setup_child()) {
worker_thread_count = 0;
for (i=0; i < ap_threads_per_child; i++) {
if (one_process) {
set_signals();
(void*)slot);
#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_daemons_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_daemons_limit; ++i) {
child_slot = i;
for (j = 0; j < HARD_THREAD_LIMIT; j++) {
if (child_slot >= 0) {
else if (is_graceful) {
else if (remaining_children_to_start) {
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;) {
if (!is_graceful) {
static int restart_num = 0;
int no_detach = 0;
is_graceful = 0;
beosd_detach();
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 }