mpm_netware.c revision 09a1167b8cb70e15be9f661f9e83ee33cfe062de
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * http://www.apache.org/licenses/LICENSE-2.0
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Unless required by applicable law or agreed to in writing, software
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distributed under the License is distributed on an "AS IS" BASIS,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * See the License for the specific language governing permissions and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * limitations under the License.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/*
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * httpd.c: simple http daemon for answering WWW file requests
e8f95a682820a599fe41b22977010636be5c2717jim *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
e8f95a682820a599fe41b22977010636be5c2717jim * 03-21-93 Rob McCool wrote original code (up to NCSA HTTPd 1.3)
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fielding *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 03-06-95 blong
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * changed server number for child-alone processes to 0 and changed name
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * of processes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 03-10-95 blong
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Added numerous speed hacks proposed by Robert S. Thau (rst@ai.mit.edu)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * including set group before fork, and call gettime before to fork
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * to set up libraries.
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 04-14-95 rst / rh
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Brandon's code snarfed from NCSA 1.4, but tinkered to work with the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Apache server, and also to have child processes do accept() directly.
5c0419d51818eb02045cf923a9fe456127a44c60wrowe *
5c0419d51818eb02045cf923a9fe456127a44c60wrowe * April-July '95 rst
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Extensive rework for Apache.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr.h"
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#include "apr_portable.h"
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#include "apr_strings.h"
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick#include "apr_thread_proc.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_signal.h"
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#include "apr_tables.h"
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#include "apr_getopt.h"
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim#include "apr_thread_mutex.h"
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#define APR_WANT_STDIO
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#define APR_WANT_STRFUNC
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#include "apr_want.h"
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
bede2929837dfd23863ad4b39199c63126566d61jorton#if APR_HAVE_UNISTD_H
0f60998368b493f90120180a93fc2e1e74490872covener#include <unistd.h>
0f60998368b493f90120180a93fc2e1e74490872covener#endif
0f60998368b493f90120180a93fc2e1e74490872covener#if APR_HAVE_SYS_TYPES_H
0f60998368b493f90120180a93fc2e1e74490872covener#include <sys/types.h>
0f60998368b493f90120180a93fc2e1e74490872covener#endif
0f60998368b493f90120180a93fc2e1e74490872covener
0f60998368b493f90120180a93fc2e1e74490872covener#ifndef USE_WINSOCK
0f60998368b493f90120180a93fc2e1e74490872covener#include <sys/select.h>
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim#endif
87587593f1a53030e840acc0dec6cc881022ea40covener
87587593f1a53030e840acc0dec6cc881022ea40covener#include "ap_config.h"
87587593f1a53030e840acc0dec6cc881022ea40covener#include "httpd.h"
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener#include "mpm_default.h"
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener#include "http_main.h"
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener#include "http_log.h"
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "http_config.h"
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "http_core.h" /* for get_remote_host */
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "http_connection.h"
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "scoreboard.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "ap_mpm.h"
43997561b2302d13dee973998e77743a3ddd2374trawick#include "mpm_common.h"
fa123db15501821e36e513afa78e839775ad2800covener#include "ap_listen.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "ap_mmn.h"
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton#ifdef HAVE_TIME_H
0568280364eb026393be492ebc732795c4934643jorton#include <time.h>
0568280364eb026393be492ebc732795c4934643jorton#endif
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton#include <signal.h>
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton#include <netware.h>
0568280364eb026393be492ebc732795c4934643jorton#include <nks/netware.h>
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include <library.h>
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include <screen.h>
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesint nlmUnloadSignaled(int wait);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Limit on the total --- clients will be locked out if more servers than
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * this are needed. It is intended solely to keep the server from crashing
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * when things get out of hand.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
796e4a7141265d8ed7036e4628161c6eafb2a789jorton * We keep a hard maximum number of servers, for two reasons --- first off,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * in case something goes seriously wrong, we want to stop the fork bomb
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * short of actually crashing the machine we're running on by filling some
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * kernel table. Secondly, it keeps the size of the scoreboard file small
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * enough that we can read the whole thing without worrying too much about
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the overhead.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifndef HARD_SERVER_LIMIT
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define HARD_SERVER_LIMIT 1
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define WORKER_DEAD SERVER_DEAD
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define WORKER_STARTING SERVER_STARTING
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define WORKER_READY SERVER_READY
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define WORKER_IDLE_KILL SERVER_IDLE_KILL
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#define MPM_HARD_LIMITS_FILE "/mpm_default.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin/* config globals */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesserver_rec *ap_server_conf;
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* *Non*-shared http_main globals... */
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int ap_threads_per_child=0; /* Worker threads per child */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int ap_threads_to_start=0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int ap_threads_min_free=0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int ap_threads_max_free=0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int ap_threads_limit=0;
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrinstatic int mpm_state = AP_MPMQ_STARTING;
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin/*
a1790fb35c4b352dab721370985c623a9f8f5062rpluem * The max child slot ever assigned, preserved across restarts. Necessary
713a2b68bac4aeb1e9c48785006c0732451039depquerna * to deal with MaxClients changes across SIGWINCH restarts. We use this
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * value to optimize routines that have to scan the entire scoreboard.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int ap_max_workers_limit = -1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesint hold_screen_on_exit = 0; /* Indicates whether the screen should be held open */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowestatic fd_set listenfds;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int listenmaxfd;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic apr_pool_t *pconf; /* Pool for config stuff */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic apr_pool_t *pmain; /* Pool for httpd child stuff */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic pid_t ap_my_pid; /* it seems silly to call getpid all the time */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic char *ap_my_addrspace = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int die_now = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* Keep track of the number of worker threads currently active */
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholesstatic unsigned long worker_thread_count;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int request_count;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe/* Structure used to register/deregister a console handler with the OS */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int InstallConsoleHandler(void);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void RemoveConsoleHandler(void);
fa123db15501821e36e513afa78e839775ad2800covenerstatic int CommandLineInterpreter(scr_t screenID, const char *commandLine);
fa123db15501821e36e513afa78e839775ad2800covenerstatic CommandParser_t ConsoleHandler = {0, NULL, 0};
fa123db15501821e36e513afa78e839775ad2800covener#define HANDLEDCOMMAND 0
fa123db15501821e36e513afa78e839775ad2800covener#define NOTMYCOMMAND 1
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
fa123db15501821e36e513afa78e839775ad2800covenerstatic int show_settings = 0;
307219eca940aa30b873bfd68a44484dd3d3fa88covener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener//#define DBINFO_ON
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim//#define DBPRINT_ON
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#ifdef DBPRINT_ON
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener#define DBPRINT0(s) printf(s)
307219eca940aa30b873bfd68a44484dd3d3fa88covener#define DBPRINT1(s,v1) printf(s,v1)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define DBPRINT2(s,v1,v2) printf(s,v1,v2)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#else
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define DBPRINT0(s)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#define DBPRINT1(s,v1)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define DBPRINT2(s,v1,v2)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* volatile just in case */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int volatile shutdown_pending;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int volatile restart_pending;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int volatile is_graceful;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int volatile wait_to_finish=1;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowestatic ap_generation_t volatile ap_my_generation=0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* a clean exit from a child with proper cleanup */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void clean_child_exit(int code, int worker_num, apr_pool_t *ptrans,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_bucket_alloc_t *bucket_alloc) __attribute__ ((noreturn));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void clean_child_exit(int code, int worker_num, apr_pool_t *ptrans,
307219eca940aa30b873bfd68a44484dd3d3fa88covener apr_bucket_alloc_t *bucket_alloc)
307219eca940aa30b873bfd68a44484dd3d3fa88covener{
307219eca940aa30b873bfd68a44484dd3d3fa88covener apr_bucket_alloc_destroy(bucket_alloc);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!shutdown_pending) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_pool_destroy(ptrans);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes atomic_dec (&worker_thread_count);
fa123db15501821e36e513afa78e839775ad2800covener if (worker_num >=0)
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener ap_update_child_status_from_indexes(0, worker_num, WORKER_DEAD,
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf (request_rec *) NULL);
fa123db15501821e36e513afa78e839775ad2800covener NXThreadExit((void*)&code);
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener}
f2be127030aa4190033084f0a6add531c9bc41desf
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/* proper cleanup when returning from ap_mpm_run() */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic void mpm_main_cleanup(void)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (pmain) {
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener apr_pool_destroy(pmain);
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int netware_query(int query_code, int *result, apr_status_t *rv)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *rv = APR_SUCCESS;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener switch(query_code){
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_MAX_DAEMON_USED:
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim *result = 1;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
6683642c1e0032eeeed5f99e8c14880692ef84c5sf case AP_MPMQ_IS_THREADED:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = AP_MPMQ_DYNAMIC;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_IS_FORKED:
6683642c1e0032eeeed5f99e8c14880692ef84c5sf *result = AP_MPMQ_NOT_SUPPORTED;
6683642c1e0032eeeed5f99e8c14880692ef84c5sf break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_HARD_LIMIT_DAEMONS:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = HARD_SERVER_LIMIT;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_HARD_LIMIT_THREADS:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = HARD_THREAD_LIMIT;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_MAX_THREADS:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = ap_threads_limit;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_MIN_SPARE_DAEMONS:
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim *result = 0;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim case AP_MPMQ_MIN_SPARE_THREADS:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = ap_threads_min_free;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_MAX_SPARE_DAEMONS:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = 0;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case AP_MPMQ_MAX_SPARE_THREADS:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *result = ap_threads_max_free;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_MAX_REQUESTS_DAEMON:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = ap_max_requests_per_child;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_MAX_DAEMONS:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = 1;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_MPM_STATE:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = mpm_state;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case AP_MPMQ_GENERATION:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener *result = ap_my_generation;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener default:
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim *rv = APR_ENOTIMPL;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return OK;
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic apr_status_t netware_note_child_killed(int childnum)
0e05808dc59a321566303084c84b9826a4353cefrederpj{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_scoreboard_image->parent[childnum].pid = 0;
b08925593f214f621161742925dcf074a8047e0acovener return APR_SUCCESS;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
465bb68501690d7a47bfd2a6129580047d76d8f1rederpjstatic const char *netware_get_name(void)
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim{
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj return "NetWare";
e8f95a682820a599fe41b22977010636be5c2717jim}
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes/*****************************************************************
55e2e59e5910072e51c870afc68b0907f41a28e0sf * Connection structures and accounting...
55e2e59e5910072e51c870afc68b0907f41a28e0sf */
55e2e59e5910072e51c870afc68b0907f41a28e0sf
55e2e59e5910072e51c870afc68b0907f41a28e0sfstatic void mpm_term(void)
55e2e59e5910072e51c870afc68b0907f41a28e0sf{
55e2e59e5910072e51c870afc68b0907f41a28e0sf RemoveConsoleHandler();
55e2e59e5910072e51c870afc68b0907f41a28e0sf wait_to_finish = 0;
55e2e59e5910072e51c870afc68b0907f41a28e0sf NXThreadYield();
55e2e59e5910072e51c870afc68b0907f41a28e0sf}
55e2e59e5910072e51c870afc68b0907f41a28e0sf
55e2e59e5910072e51c870afc68b0907f41a28e0sfstatic void sig_term(int sig)
55e2e59e5910072e51c870afc68b0907f41a28e0sf{
55e2e59e5910072e51c870afc68b0907f41a28e0sf if (shutdown_pending == 1) {
55e2e59e5910072e51c870afc68b0907f41a28e0sf /* Um, is this _probably_ not an error, if the user has
55e2e59e5910072e51c870afc68b0907f41a28e0sf * tried to do a shutdown twice quickly, so we won't
55e2e59e5910072e51c870afc68b0907f41a28e0sf * worry about reporting it.
55e2e59e5910072e51c870afc68b0907f41a28e0sf */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes shutdown_pending = 1;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes DBPRINT0 ("waiting for threads\n");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes while (wait_to_finish) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_thread_yield();
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes DBPRINT0 ("goodbye\n");
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf}
55e2e59e5910072e51c870afc68b0907f41a28e0sf
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* restart() is the signal handler for SIGHUP and SIGWINCH
513b324e774c559b579896df131fd7c8471ed529rederpj * in the parent process, unless running in ONE_PROCESS mode
513b324e774c559b579896df131fd7c8471ed529rederpj */
513b324e774c559b579896df131fd7c8471ed529rederpjstatic void restart(void)
513b324e774c559b579896df131fd7c8471ed529rederpj{
513b324e774c559b579896df131fd7c8471ed529rederpj if (restart_pending == 1) {
513b324e774c559b579896df131fd7c8471ed529rederpj /* Probably not an error - don't bother reporting it */
513b324e774c559b579896df131fd7c8471ed529rederpj return;
513b324e774c559b579896df131fd7c8471ed529rederpj }
513b324e774c559b579896df131fd7c8471ed529rederpj restart_pending = 1;
513b324e774c559b579896df131fd7c8471ed529rederpj is_graceful = 1;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
02fd88c85a9850109753b87612955ad372de1575sf
02fd88c85a9850109753b87612955ad372de1575sfstatic void set_signals(void)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_signal(SIGTERM, sig_term);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_signal(SIGABRT, sig_term);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesint nlmUnloadSignaled(int wait)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes shutdown_pending = 1;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (wait) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (wait_to_finish) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes NXThreadYield();
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
307219eca940aa30b873bfd68a44484dd3d3fa88covener
307219eca940aa30b873bfd68a44484dd3d3fa88covener return 0;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener}
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf/*****************************************************************
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * Child process main loop.
185aa71728867671e105178b4c66fbc22b65ae26sf * The following vars are static to avoid getting clobbered by longjmp();
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * they are really private to child_main.
707f6d077f73cc948deead8df5b40ea42c1eaa78covener */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener#define MAX_WB_RETRIES 3
9ad7b260be233be7d7b5576979825cac72e15498rederpj#ifdef DBINFO_ON
9ad7b260be233be7d7b5576979825cac72e15498rederpjstatic int would_block = 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic int retry_success = 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic int retry_fail = 0;
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic int avg_retries = 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif
55e2e59e5910072e51c870afc68b0907f41a28e0sf
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf/*static */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesvoid worker_main(void *arg)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_listen_rec *lr, *first_lr, *last_lr = NULL;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_pool_t *ptrans;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_allocator_t *allocator;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_bucket_alloc_t *bucket_alloc;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes conn_rec *current_conn;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_status_t stat = APR_EINIT;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_sb_handle_t *sbh;
55e2e59e5910072e51c870afc68b0907f41a28e0sf
55e2e59e5910072e51c870afc68b0907f41a28e0sf int my_worker_num = (int)arg;
55e2e59e5910072e51c870afc68b0907f41a28e0sf apr_socket_t *csd = NULL;
55e2e59e5910072e51c870afc68b0907f41a28e0sf int requests_this_child = 0;
55e2e59e5910072e51c870afc68b0907f41a28e0sf apr_socket_t *sd = NULL;
55e2e59e5910072e51c870afc68b0907f41a28e0sf fd_set main_fds;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf int sockdes;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes int srv;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes struct timeval tv;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes int wouldblock_retry;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes tv.tv_sec = 1;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes tv.tv_usec = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_allocator_create(&allocator);
b08925593f214f621161742925dcf074a8047e0acovener apr_allocator_max_free_set(allocator, ap_max_mem_free);
b08925593f214f621161742925dcf074a8047e0acovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_pool_create_ex(&ptrans, pmain, NULL, allocator);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim apr_allocator_owner_set(allocator, ptrans);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener apr_pool_tag(ptrans, "transaction");
185aa71728867671e105178b4c66fbc22b65ae26sf
707f6d077f73cc948deead8df5b40ea42c1eaa78covener bucket_alloc = apr_bucket_alloc_create_ex(allocator);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf atomic_inc (&worker_thread_count);
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
707f6d077f73cc948deead8df5b40ea42c1eaa78covener while (!die_now) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener /*
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * (Re)initialize this child to a pre-connection state.
9ad7b260be233be7d7b5576979825cac72e15498rederpj */
185aa71728867671e105178b4c66fbc22b65ae26sf current_conn = NULL;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener apr_pool_clear(ptrans);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if ((ap_max_requests_per_child > 0
707f6d077f73cc948deead8df5b40ea42c1eaa78covener && requests_this_child++ >= ap_max_requests_per_child)) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener DBPRINT1 ("\n**Thread slot %d is shutting down", my_worker_num);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener clean_child_exit(0, my_worker_num, ptrans, bucket_alloc);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener ap_update_child_status_from_indexes(0, my_worker_num, WORKER_READY,
707f6d077f73cc948deead8df5b40ea42c1eaa78covener (request_rec *) NULL);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
185aa71728867671e105178b4c66fbc22b65ae26sf /*
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * Wait for an acceptable connection to arrive.
707f6d077f73cc948deead8df5b40ea42c1eaa78covener */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf for (;;) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (shutdown_pending || restart_pending || (ap_scoreboard_image->servers[0][my_worker_num].status == WORKER_IDLE_KILL)) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener DBPRINT1 ("\nThread slot %d is shutting down\n", my_worker_num);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener clean_child_exit(0, my_worker_num, ptrans, bucket_alloc);
185aa71728867671e105178b4c66fbc22b65ae26sf }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener /* Check the listen queue on all sockets for requests */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener memcpy(&main_fds, &listenfds, sizeof(fd_set));
707f6d077f73cc948deead8df5b40ea42c1eaa78covener srv = select(listenmaxfd + 1, &main_fds, NULL, NULL, &tv);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (srv <= 0) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (srv < 0) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
9ad7b260be233be7d7b5576979825cac72e15498rederpj "select() failed on listen socket");
9ad7b260be233be7d7b5576979825cac72e15498rederpj apr_thread_yield();
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf continue;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* remember the last_lr we searched last time around so that
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf we don't end up starving any particular listening socket */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (last_lr == NULL) {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf lr = ap_listeners;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf else {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf lr = last_lr->next;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (!lr)
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf lr = ap_listeners;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf first_lr = lr;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf do {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf apr_os_sock_get(&sockdes, lr->sd);
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (FD_ISSET(sockdes, &main_fds))
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf goto got_listener;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf lr = lr->next;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (!lr)
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf lr = ap_listeners;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf } while (lr != first_lr);
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf /* if we get here, something unexpected happened. Go back
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf into the select state and try again.
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf */
141e1368614dc7564e1627671361b01b4869b491bnicholes continue;
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes got_listener:
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes last_lr = lr;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf sd = lr->sd;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
e8f95a682820a599fe41b22977010636be5c2717jim wouldblock_retry = MAX_WB_RETRIES;
1ae7a5fbce5d4f65f3da355792258fe5dbc4ef55covener
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf while (wouldblock_retry) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf if ((stat = apr_socket_accept(&csd, sd, ptrans)) == APR_SUCCESS) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes break;
185aa71728867671e105178b4c66fbc22b65ae26sf }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes else {
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes /* if the error is a wouldblock then maybe we were too
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes quick try to pull the next request from the listen
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes queue. Try a few more times then return to our idle
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes listen state. */
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf if (!APR_STATUS_IS_EAGAIN(stat)) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf break;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf if (wouldblock_retry--) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf apr_thread_yield();
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf /* If we got a new socket, set it to non-blocking mode and process
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf it. Otherwise handle the error. */
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf if (stat == APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf apr_socket_opt_set(csd, APR_SO_NONBLOCK, 0);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf#ifdef DBINFO_ON
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf if (wouldblock_retry < MAX_WB_RETRIES) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf retry_success++;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf avg_retries += (MAX_WB_RETRIES-wouldblock_retry);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes break; /* We have a socket ready for reading */
e8f95a682820a599fe41b22977010636be5c2717jim }
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim else {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim#ifdef DBINFO_ON
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener if (APR_STATUS_IS_EAGAIN(stat)) {
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener would_block++;
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener retry_fail++;
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener }
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener else if (
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener#else
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener if (APR_STATUS_IS_EAGAIN(stat) ||
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener#endif
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener APR_STATUS_IS_ECONNRESET(stat) ||
783874b86bfe13d7a4fe0922f344a3779cdccea3covener APR_STATUS_IS_ETIMEDOUT(stat) ||
7dbf29be626018bc389ef94c1846aeac4b72633bsf APR_STATUS_IS_EHOSTUNREACH(stat) ||
7dbf29be626018bc389ef94c1846aeac4b72633bsf APR_STATUS_IS_ENETUNREACH(stat)) {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim ;
7dbf29be626018bc389ef94c1846aeac4b72633bsf }
7dbf29be626018bc389ef94c1846aeac4b72633bsf#ifdef USE_WINSOCK
7dbf29be626018bc389ef94c1846aeac4b72633bsf else if (APR_STATUS_IS_ENETDOWN(stat)) {
7dbf29be626018bc389ef94c1846aeac4b72633bsf /*
7dbf29be626018bc389ef94c1846aeac4b72633bsf * When the network layer has been shut down, there
7dbf29be626018bc389ef94c1846aeac4b72633bsf * is not much use in simply exiting: the parent
7dbf29be626018bc389ef94c1846aeac4b72633bsf * would simply re-create us (and we'd fail again).
7dbf29be626018bc389ef94c1846aeac4b72633bsf * Use the CHILDFATAL code to tear the server down.
7dbf29be626018bc389ef94c1846aeac4b72633bsf * @@@ Martin's idea for possible improvement:
7dbf29be626018bc389ef94c1846aeac4b72633bsf * A different approach would be to define
7dbf29be626018bc389ef94c1846aeac4b72633bsf * a new APEXIT_NETDOWN exit code, the reception
7dbf29be626018bc389ef94c1846aeac4b72633bsf * of which would make the parent shutdown all
783874b86bfe13d7a4fe0922f344a3779cdccea3covener * children, then idle-loop until it detected that
7dbf29be626018bc389ef94c1846aeac4b72633bsf * the network is up again, and restart the children.
7dbf29be626018bc389ef94c1846aeac4b72633bsf * Ben Hyde noted that temporary ENETDOWN situations
7dbf29be626018bc389ef94c1846aeac4b72633bsf * occur in mobile IP.
7dbf29be626018bc389ef94c1846aeac4b72633bsf */
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_log_error(APLOG_MARK, APLOG_EMERG, stat, ap_server_conf,
783874b86bfe13d7a4fe0922f344a3779cdccea3covener "apr_socket_accept: giving up.");
7dbf29be626018bc389ef94c1846aeac4b72633bsf clean_child_exit(APEXIT_CHILDFATAL, my_worker_num, ptrans,
7dbf29be626018bc389ef94c1846aeac4b72633bsf bucket_alloc);
7dbf29be626018bc389ef94c1846aeac4b72633bsf }
7dbf29be626018bc389ef94c1846aeac4b72633bsf#endif
7dbf29be626018bc389ef94c1846aeac4b72633bsf else {
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_log_error(APLOG_MARK, APLOG_ERR, stat, ap_server_conf,
7dbf29be626018bc389ef94c1846aeac4b72633bsf "apr_socket_accept: (client socket)");
783874b86bfe13d7a4fe0922f344a3779cdccea3covener clean_child_exit(1, my_worker_num, ptrans, bucket_alloc);
7dbf29be626018bc389ef94c1846aeac4b72633bsf }
307219eca940aa30b873bfd68a44484dd3d3fa88covener }
307219eca940aa30b873bfd68a44484dd3d3fa88covener }
307219eca940aa30b873bfd68a44484dd3d3fa88covener
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_create_sb_handle(&sbh, ptrans, 0, my_worker_num);
7dbf29be626018bc389ef94c1846aeac4b72633bsf /*
7dbf29be626018bc389ef94c1846aeac4b72633bsf * We now have a connection, so set it up with the appropriate
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * socket options, file descriptors, and read/write buffers.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes my_worker_num, sbh,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes bucket_alloc);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (current_conn) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_process_connection(current_conn, csd);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_lingering_close(current_conn);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes request_count++;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf clean_child_exit(0, my_worker_num, ptrans, bucket_alloc);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic int make_child(server_rec *s, int slot)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes int tid;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes int err=0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes NXContext_t ctx;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
307219eca940aa30b873bfd68a44484dd3d3fa88covener if (slot + 1 > ap_max_workers_limit) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_max_workers_limit = slot + 1;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_update_child_status_from_indexes(0, slot, WORKER_STARTING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes (request_rec *) NULL);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (ctx = NXContextAlloc((void (*)(void *)) worker_main, (void*)slot, NX_PRIO_MED, ap_thread_stacksize, NX_CTX_NORMAL, &err)) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char threadName[32];
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf sprintf (threadName, "Apache_Worker %d", slot);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes NXContextSetName(ctx, threadName);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes err = NXThreadCreate(ctx, NX_THR_BIND_CONTEXT, &tid);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (err) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes NXContextFree (ctx);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (err) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf /* create thread didn't succeed. Fix the scoreboard or else
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf * it will say SERVER_STARTING forever and ever
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf */
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_update_child_status_from_indexes(0, slot, WORKER_DEAD,
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener (request_rec *) NULL);
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf /* In case system resources are maxxed out, we don't want
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf Apache running away with the CPU trying to fork over and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes over and over again. */
e8f95a682820a599fe41b22977010636be5c2717jim apr_thread_yield();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return -1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_scoreboard_image->servers[0][slot].tid = tid;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim return 0;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener}
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
7dbf29be626018bc389ef94c1846aeac4b72633bsf
7dbf29be626018bc389ef94c1846aeac4b72633bsf/* start up a bunch of worker threads */
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covenerstatic void startup_workers(int number_to_start)
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener{
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener int i;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener for (i = 0; number_to_start && i < ap_threads_limit; ++i) {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (ap_scoreboard_image->servers[0][i].status != WORKER_DEAD) {
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener continue;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener if (make_child(ap_server_conf, i) < 0) {
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener break;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
185aa71728867671e105178b4c66fbc22b65ae26sf --number_to_start;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim}
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim/*
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener * idle_spawn_rate is the number of children that will be spawned on the
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener * next maintenance cycle if there aren't enough idle servers. It is
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener * without the need to spawn.
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener */
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jimstatic int idle_spawn_rate = 1;
9c63a05713cb83a44a1590b4af33edeebf39f118sf#ifndef MAX_SPAWN_RATE
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener#define MAX_SPAWN_RATE (64)
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim#endif
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covenerstatic int hold_off_on_exponential_spawning;
9c63a05713cb83a44a1590b4af33edeebf39f118sf
9c63a05713cb83a44a1590b4af33edeebf39f118sfstatic void perform_idle_server_maintenance(apr_pool_t *p)
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf{
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim int i;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int idle_count;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes worker_score *ws;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int free_length;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin int free_slots[MAX_SPAWN_RATE];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int last_non_dead;
9c63a05713cb83a44a1590b4af33edeebf39f118sf int total_non_dead;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* initialize the free_list */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes free_length = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
307219eca940aa30b873bfd68a44484dd3d3fa88covener idle_count = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes last_non_dead = -1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes total_non_dead = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
54d22ed1c429b903b029bbd62621f11a9e286137minfrin for (i = 0; i < ap_threads_limit; ++i) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin int status;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (i >= ap_max_workers_limit && free_length == idle_spawn_rate)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin break;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ws = &ap_scoreboard_image->servers[0][i];
54d22ed1c429b903b029bbd62621f11a9e286137minfrin status = ws->status;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (status == WORKER_DEAD) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* try to keep children numbers as low as possible */
e8f95a682820a599fe41b22977010636be5c2717jim if (free_length < idle_spawn_rate) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe free_slots[free_length] = i;
8a03cd420b800a2428f49f4617293de9b2387b20jorton ++free_length;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (status == WORKER_IDLE_KILL) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* If it is already marked to die, skip it */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin continue;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* We consider a starting server as idle because we started it
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * at least a cycle ago, and if it still hasn't finished starting
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * then we're just going to swamp things worse by forking more.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * So we hopefully won't need to fork more if we count it.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * This depends on the ordering of SERVER_READY and SERVER_STARTING.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (status <= WORKER_READY) {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf ++ idle_count;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener ++total_non_dead;
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener last_non_dead = i;
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener }
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener }
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener DBPRINT2("Total: %d Idle Count: %d \r", total_non_dead, idle_count);
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener ap_max_workers_limit = last_non_dead + 1;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (idle_count > ap_threads_max_free) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* kill off one child... we use the pod because that'll cause it to
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * shut down gracefully, in case it happened to pick up a request
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * while we were counting
54d22ed1c429b903b029bbd62621f11a9e286137minfrin */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin idle_spawn_rate = 1;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_update_child_status_from_indexes(0, last_non_dead, WORKER_IDLE_KILL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (request_rec *) NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes DBPRINT1("\nKilling idle thread: %d\n", last_non_dead);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else if (idle_count < ap_threads_min_free) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* terminate the free list */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (free_length == 0) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* only report this condition once */
e8f95a682820a599fe41b22977010636be5c2717jim static int reported = 0;
e8f95a682820a599fe41b22977010636be5c2717jim
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (!reported) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
e8f95a682820a599fe41b22977010636be5c2717jim "server reached MaxClients setting, consider"
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe " raising the MaxClients setting");
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe reported = 1;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
f0f6f1b90ab582896f8a7d56d85bd62a55e57d90covener idle_spawn_rate = 1;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else {
560fd0658902ab57754616c172d8953e69fc4722bnicholes if (idle_spawn_rate >= 8) {
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "server seems busy, (you may need "
e8f95a682820a599fe41b22977010636be5c2717jim "to increase StartServers, or Min/MaxSpareServers), "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "spawning %d children, there are %d idle, and "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "%d total children", idle_spawn_rate,
9ad7b260be233be7d7b5576979825cac72e15498rederpj idle_count, total_non_dead);
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes DBPRINT0("\n");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (i = 0; i < free_length; ++i) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes DBPRINT1("Spawning additional thread slot: %d\n", free_slots[i]);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes make_child(ap_server_conf, free_slots[i]);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* the next time around we want to spawn twice as many if this
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * wasn't good enough, but not if we've just done a graceful
560fd0658902ab57754616c172d8953e69fc4722bnicholes */
560fd0658902ab57754616c172d8953e69fc4722bnicholes if (hold_off_on_exponential_spawning) {
560fd0658902ab57754616c172d8953e69fc4722bnicholes --hold_off_on_exponential_spawning;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else if (idle_spawn_rate < MAX_SPAWN_RATE) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes idle_spawn_rate *= 2;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else {
e8f95a682820a599fe41b22977010636be5c2717jim idle_spawn_rate = 1;
e8f95a682820a599fe41b22977010636be5c2717jim }
e8f95a682820a599fe41b22977010636be5c2717jim}
e8f95a682820a599fe41b22977010636be5c2717jim
e8f95a682820a599fe41b22977010636be5c2717jimstatic void display_settings()
e8f95a682820a599fe41b22977010636be5c2717jim{
ae1981fc94adf2b231e2d0e15d2f895b2138c969covener int status_array[SERVER_NUM_STATUS];
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe int i, status, total=0;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim int reqs = request_count;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim#ifdef DBINFO_ON
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim int wblock = would_block;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener would_block = 0;
307219eca940aa30b873bfd68a44484dd3d3fa88covener#endif
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener
54091ac5c596337658fc568231ca1a900abdc5fecovener request_count = 0;
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener
307219eca940aa30b873bfd68a44484dd3d3fa88covener ClearScreen (getscreenhandle());
307219eca940aa30b873bfd68a44484dd3d3fa88covener printf("%s \n", ap_get_server_description());
307219eca940aa30b873bfd68a44484dd3d3fa88covener
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener for (i=0;i<SERVER_NUM_STATUS;i++) {
54091ac5c596337658fc568231ca1a900abdc5fecovener status_array[i] = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (i = 0; i < ap_threads_limit; ++i) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes status = (ap_scoreboard_image->servers[0][i]).status;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes status_array[status]++;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (i=0;i<SERVER_NUM_STATUS;i++) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes switch(i)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case SERVER_DEAD:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Available:\t%d\n", status_array[i]);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case SERVER_STARTING:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Starting:\t%d\n", status_array[i]);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case SERVER_READY:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Ready:\t\t%d\n", status_array[i]);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case SERVER_BUSY_READ:
e8f95a682820a599fe41b22977010636be5c2717jim printf ("Busy:\t\t%d\n", status_array[i]);
560fd0658902ab57754616c172d8953e69fc4722bnicholes break;
ae1981fc94adf2b231e2d0e15d2f895b2138c969covener case SERVER_BUSY_WRITE:
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe printf ("Busy Write:\t%d\n", status_array[i]);
307219eca940aa30b873bfd68a44484dd3d3fa88covener break;
307219eca940aa30b873bfd68a44484dd3d3fa88covener case SERVER_BUSY_KEEPALIVE:
307219eca940aa30b873bfd68a44484dd3d3fa88covener printf ("Busy Keepalive:\t%d\n", status_array[i]);
307219eca940aa30b873bfd68a44484dd3d3fa88covener break;
307219eca940aa30b873bfd68a44484dd3d3fa88covener case SERVER_BUSY_LOG:
307219eca940aa30b873bfd68a44484dd3d3fa88covener printf ("Busy Log:\t%d\n", status_array[i]);
307219eca940aa30b873bfd68a44484dd3d3fa88covener break;
307219eca940aa30b873bfd68a44484dd3d3fa88covener case SERVER_BUSY_DNS:
307219eca940aa30b873bfd68a44484dd3d3fa88covener printf ("Busy DNS:\t%d\n", status_array[i]);
307219eca940aa30b873bfd68a44484dd3d3fa88covener break;
307219eca940aa30b873bfd68a44484dd3d3fa88covener case SERVER_CLOSING:
307219eca940aa30b873bfd68a44484dd3d3fa88covener printf ("Closing:\t%d\n", status_array[i]);
307219eca940aa30b873bfd68a44484dd3d3fa88covener break;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim case SERVER_GRACEFUL:
307219eca940aa30b873bfd68a44484dd3d3fa88covener printf ("Restart:\t%d\n", status_array[i]);
307219eca940aa30b873bfd68a44484dd3d3fa88covener break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case SERVER_IDLE_KILL:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Idle Kill:\t%d\n", status_array[i]);
307219eca940aa30b873bfd68a44484dd3d3fa88covener break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes default:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Unknown Status:\t%d\n", status_array[i]);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (i != SERVER_DEAD)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes total+=status_array[i];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Total Running:\t%d\tout of: \t%d\n", total, ap_threads_limit);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Requests per interval:\t%d\n", reqs);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef DBINFO_ON
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Would blocks:\t%d\n", wblock);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Successful retries:\t%d\n", retry_success);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Failed retries:\t%d\n", retry_fail);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("Avg retries:\t%d\n", retry_success == 0 ? 0 : avg_retries / retry_success);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
0e05808dc59a321566303084c84b9826a4353cefrederpj}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void show_server_data()
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener ap_listen_rec *lr;
0e05808dc59a321566303084c84b9826a4353cefrederpj module **m;
185aa71728867671e105178b4c66fbc22b65ae26sf
ebe5305f8b22507374358f32b74d12fb50c05a25covener printf("%s\n", ap_get_server_description());
ebe5305f8b22507374358f32b74d12fb50c05a25covener if (ap_my_addrspace && (ap_my_addrspace[0] != 'O') && (ap_my_addrspace[1] != 'S'))
ebe5305f8b22507374358f32b74d12fb50c05a25covener printf(" Running in address space %s\n", ap_my_addrspace);
ebe5305f8b22507374358f32b74d12fb50c05a25covener
ebe5305f8b22507374358f32b74d12fb50c05a25covener
ebe5305f8b22507374358f32b74d12fb50c05a25covener /* Display listening ports */
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim printf(" Listening on port(s):");
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener lr = ap_listeners;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener do {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener printf(" %d", lr->bind_addr->port);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener lr = lr->next;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener } while(lr && lr != ap_listeners);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* Display dynamic modules loaded */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener printf("\n");
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener for (m = ap_loaded_modules; *m != NULL; m++) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (((module*)*m)->dynamic_load_handle) {
0e05808dc59a321566303084c84b9826a4353cefrederpj printf(" Loaded dynamic module %s\n", ((module*)*m)->name);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int setup_listeners(server_rec *s)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_listen_rec *lr;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int sockdes;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
9ad7b260be233be7d7b5576979825cac72e15498rederpj if (ap_setup_listeners(s) < 1 ) {
9ad7b260be233be7d7b5576979825cac72e15498rederpj ap_log_error(APLOG_MARK, APLOG_ALERT, 0, s,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "no listening sockets available, shutting down");
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return -1;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin listenmaxfd = -1;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin FD_ZERO(&listenfds);
560fd0658902ab57754616c172d8953e69fc4722bnicholes for (lr = ap_listeners; lr; lr = lr->next) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_os_sock_get(&sockdes, lr->sd);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin FD_SET(sockdes, &listenfds);
ae1981fc94adf2b231e2d0e15d2f895b2138c969covener if (sockdes > listenmaxfd) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes listenmaxfd = sockdes;
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener }
7a55c294da84865fe13262ed66ffd0c5841a9da5covener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return 0;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim}
fa123db15501821e36e513afa78e839775ad2800covener
185aa71728867671e105178b4c66fbc22b65ae26sfstatic int shutdown_listeners()
fa123db15501821e36e513afa78e839775ad2800covener{
fa123db15501821e36e513afa78e839775ad2800covener ap_listen_rec *lr;
fa123db15501821e36e513afa78e839775ad2800covener
fa123db15501821e36e513afa78e839775ad2800covener for (lr = ap_listeners; lr; lr = lr->next) {
fa123db15501821e36e513afa78e839775ad2800covener apr_socket_close(lr->sd);
fa123db15501821e36e513afa78e839775ad2800covener }
fa123db15501821e36e513afa78e839775ad2800covener ap_listeners = NULL;
fa123db15501821e36e513afa78e839775ad2800covener return 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/*****************************************************************
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Executive routines.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int netware_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_status_t status=0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pconf = _pconf;
307219eca940aa30b873bfd68a44484dd3d3fa88covener ap_server_conf = s;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (setup_listeners(s)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_ALERT, status, s,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "no listening sockets available, shutting down");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return -1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe restart_pending = shutdown_pending = 0;
e8f95a682820a599fe41b22977010636be5c2717jim worker_thread_count = 0;
e8f95a682820a599fe41b22977010636be5c2717jim
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (!is_graceful) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_run_pre_mpm(s->process->pool, SB_NOT_SHARED) != OK) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return 1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim }
e8f95a682820a599fe41b22977010636be5c2717jim
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe /* Only set slot 0 since that is all NetWare will ever have. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_scoreboard_image->parent[0].pid = getpid();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
e8f95a682820a599fe41b22977010636be5c2717jim set_signals();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_pool_create(&pmain, pconf);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_run_child_init(pmain, ap_server_conf);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_threads_max_free < ap_threads_min_free + 1) /* Don't thrash... */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_max_free = ap_threads_min_free + 1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes request_count = 0;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
e8f95a682820a599fe41b22977010636be5c2717jim startup_workers(ap_threads_to_start);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Allow the Apache screen to be closed normally on exit() only if it
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes has not been explicitly forced to close on exit(). (ie. the -E flag
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes was specified at startup) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (hold_screen_on_exit > 0) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes hold_screen_on_exit = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "%s configured -- resuming normal operations",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_get_server_description());
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Server built: %s", ap_get_server_built());
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_command_line(plog, s);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes show_server_data();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes mpm_state = AP_MPMQ_RUNNING;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (!restart_pending && !shutdown_pending) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes perform_idle_server_maintenance(pconf);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (show_settings)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes display_settings();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_thread_yield();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_sleep(SCOREBOARD_MAINTENANCE_INTERVAL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes mpm_state = AP_MPMQ_STOPPING;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Shutdown the listen sockets so that we don't get stuck in a blocking call.
e8f95a682820a599fe41b22977010636be5c2717jim shutdown_listeners();*/
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (shutdown_pending) { /* Got an unload from the console */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "caught SIGTERM, shutting down");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (worker_thread_count > 0) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("\rShutdown pending. Waiting for %d thread(s) to terminate...",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes worker_thread_count);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_thread_yield();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes mpm_main_cleanup();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return 1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else { /* the only other way out is a restart */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* advance to the next generation */
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener /* XXX: we really need to make sure this new generation number isn't in
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * use by any of the children.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ++ap_my_generation;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_scoreboard_image->global->running_generation = ap_my_generation;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener "Graceful restart requested, doing restart");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes /* Wait for all of the threads to terminate before initiating the restart */
43c3e6a4b559b76b750c245ee95e2782c15b4296jim while (worker_thread_count > 0) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes printf ("\rRestart pending. Waiting for %d thread(s) to terminate...",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes worker_thread_count);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_thread_yield();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener printf ("\nRestarting...\n");
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener mpm_main_cleanup();
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe return 0;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe}
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholesstatic int netware_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *addrname = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf mpm_state = AP_MPMQ_STARTING;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf is_graceful = 0;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf ap_my_pid = getpid();
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf addrname = getaddressspacename (NULL, NULL);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf if (addrname) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf ap_my_addrspace = apr_pstrdup (p, addrname);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf free (addrname);
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf#ifndef USE_WINSOCK
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* The following call has been moved to the mod_nw_ssl pre-config handler */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_listen_pre_config();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_to_start = DEFAULT_START_THREADS;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_min_free = DEFAULT_MIN_FREE_THREADS;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_max_free = DEFAULT_MAX_FREE_THREADS;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_limit = HARD_THREAD_LIMIT;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_extended_status = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_thread_stacksize = DEFAULT_THREAD_STACKSIZE;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return OK;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int netware_check_config(apr_pool_t *p, apr_pool_t *plog,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_pool_t *ptemp, server_rec *s)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
e8f95a682820a599fe41b22977010636be5c2717jim static int restart_num = 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int startup = 0;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
e8f95a682820a599fe41b22977010636be5c2717jim /* we want this only the first time around */
e8f95a682820a599fe41b22977010636be5c2717jim if (restart_num++ == 0) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe startup = 1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_threads_limit > HARD_THREAD_LIMIT) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (startup) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "WARNING: MaxThreads of %d exceeds compile-time "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "limit of", ap_threads_limit);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes " %d threads, decreasing to %d.",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes HARD_THREAD_LIMIT, HARD_THREAD_LIMIT);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes " To increase, please see the HARD_THREAD_LIMIT"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "define in");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
e8f95a682820a599fe41b22977010636be5c2717jim " server/mpm/netware%s.", MPM_HARD_LIMITS_FILE);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem } else {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "MaxThreads of %d exceeds compile-time limit "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "of %d, decreasing to match",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_limit, HARD_THREAD_LIMIT);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe ap_threads_limit = HARD_THREAD_LIMIT;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes else if (ap_threads_limit < 1) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (startup) {
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "WARNING: MaxThreads of %d not allowed, "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "increasing to 1.", ap_threads_limit);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } else {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "MaxThreads of %d not allowed, increasing to 1",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_limit);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ap_threads_limit = 1;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ap_threads_to_start > ap_threads_limit effectively checked in
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * call to startup_workers(ap_threads_to_start) in ap_mpm_run()
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_threads_to_start < 0) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (startup) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "WARNING: StartThreads of %d not allowed, "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "increasing to 1.", ap_threads_to_start);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } else {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "StartThreads of %d not allowed, increasing to 1",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_to_start);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim ap_threads_to_start = 1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_threads_min_free < 1) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (startup) {
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj "WARNING: MinSpareThreads of %d not allowed, "
e8f95a682820a599fe41b22977010636be5c2717jim "increasing to 1", ap_threads_min_free);
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe " to avoid almost certain server failure.");
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes " Please read the documentation.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } else {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "MinSpareThreads of %d not allowed, increasing to 1",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_min_free);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_threads_min_free = 1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ap_threads_max_free < ap_threads_min_free + 1 checked in ap_mpm_run() */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return OK;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void netware_mpm_hooks(apr_pool_t *p)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_hook_pre_config(netware_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_hook_check_config(netware_check_config, NULL, NULL, APR_HOOK_MIDDLE);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes //ap_hook_post_config(netware_post_config, NULL, NULL, 0);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes //ap_hook_child_init(netware_child_init, NULL, NULL, APR_HOOK_MIDDLE);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj //ap_hook_open_logs(netware_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj ap_hook_mpm(netware_run, NULL, NULL, APR_HOOK_MIDDLE);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj ap_hook_mpm_query(netware_query, NULL, NULL, APR_HOOK_MIDDLE);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj ap_hook_mpm_note_child_killed(netware_note_child_killed, NULL, NULL, APR_HOOK_MIDDLE);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj ap_hook_mpm_get_name(netware_get_name, NULL, NULL, APR_HOOK_MIDDLE);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic void netware_rewrite_args(process_rec *process)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *def_server_root;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char optbuf[3];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *opt_arg;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_getopt_t *opt;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener apr_array_header_t *mpm_new_argv;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj atexit (mpm_term);
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener InstallConsoleHandler();
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener /* Make sure to hold the Apache screen open if exit() is called */
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener hold_screen_on_exit = 1;
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Rewrite process->argv[];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * add default -d serverroot from the path of this executable
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener * The end result will look like:
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener * The -d serverroot default from the running executable
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener */
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener if (process->argc > 0) {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim char *s = apr_pstrdup (process->pconf, process->argv[0]);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (s) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int i, len = strlen(s);
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener for (i=len; i; i--) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (s[i] == '\\' || s[i] == '/') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes s[i] = '\0';
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf apr_filepath_merge(&def_server_root, NULL, s,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf APR_FILEPATH_TRUENAME, process->pool);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf break;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf }
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf /* Use process->pool so that the rewritten argv
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf * lasts for the lifetime of the server process,
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener * because pconf will be destroyed after the
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf * initial pre-flight of the config parser.
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes mpm_new_argv = apr_array_make(process->pool, process->argc + 2,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes sizeof(const char *));
e8f95a682820a599fe41b22977010636be5c2717jim *(const char **)apr_array_push(mpm_new_argv) = process->argv[0];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *(const char **)apr_array_push(mpm_new_argv) = "-d";
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *(const char **)apr_array_push(mpm_new_argv) = def_server_root;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes optbuf[0] = '-';
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes optbuf[2] = '\0';
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_getopt_init(&opt, process->pool, process->argc, (char**) process->argv);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while (apr_getopt(opt, AP_SERVER_BASEARGS"n:", optbuf + 1, &opt_arg) == APR_SUCCESS) {
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj switch (optbuf[1]) {
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj case 'n':
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (opt_arg) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe renamescreen(opt_arg);
e8f95a682820a599fe41b22977010636be5c2717jim }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe break;
e8f95a682820a599fe41b22977010636be5c2717jim case 'E':
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* Don't need to hold the screen open if the output is going to a file */
e8f95a682820a599fe41b22977010636be5c2717jim hold_screen_on_exit = -1;
e8f95a682820a599fe41b22977010636be5c2717jim default:
e8f95a682820a599fe41b22977010636be5c2717jim *(const char **)apr_array_push(mpm_new_argv) =
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe apr_pstrdup(process->pool, optbuf);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj if (opt_arg) {
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj *(const char **)apr_array_push(mpm_new_argv) = opt_arg;
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem }
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem break;
9c63a05713cb83a44a1590b4af33edeebf39f118sf }
185aa71728867671e105178b4c66fbc22b65ae26sf }
9efd5708f6f0ab1992f6a5233eb622ad5e4eae18sf process->argc = mpm_new_argv->nelts;
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj process->argv = (const char * const *) mpm_new_argv->elts;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int CommandLineInterpreter(scr_t screenID, const char *commandLine)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *szCommand = "APACHE2 ";
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int iCommandLen = 8;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char szcommandLine[256];
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *pID;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes screenID = screenID;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (commandLine == NULL)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return NOTMYCOMMAND;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (strlen(commandLine) <= strlen(szCommand))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return NOTMYCOMMAND;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_cpystrn(szcommandLine, commandLine, sizeof(szcommandLine));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* All added commands begin with "APACHE2 " */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!strnicmp(szCommand, szcommandLine, iCommandLen)) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj ActivateScreen (getscreenhandle());
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* If an instance id was not given but the nlm is loaded in
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem protected space, then the the command belongs to the
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem OS address space instance to pass it on. */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem pID = strstr (szcommandLine, "-p");
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem if ((pID == NULL) && nlmisloadedprotected())
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem return NOTMYCOMMAND;
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* If we got an instance id but it doesn't match this
8869662bb1a4078297020e94ae5e928626d877c6rederpj instance of the nlm, pass it on. */
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (pID) {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem pID = &pID[2];
8869662bb1a4078297020e94ae5e928626d877c6rederpj while (*pID && (*pID == ' '))
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener pID++;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener if (pID && ap_my_addrspace && strnicmp(pID, ap_my_addrspace, strlen(ap_my_addrspace)))
8869662bb1a4078297020e94ae5e928626d877c6rederpj return NOTMYCOMMAND;
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* If we have determined that this command belongs to this
8869662bb1a4078297020e94ae5e928626d877c6rederpj instance of the nlm, then handle it. */
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (!strnicmp("RESTART",&szcommandLine[iCommandLen],3)) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj printf("Restart Requested...\n");
8869662bb1a4078297020e94ae5e928626d877c6rederpj restart();
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem else if (!strnicmp("VERSION",&szcommandLine[iCommandLen],3)) {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem printf("Server version: %s\n", ap_get_server_description());
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem printf("Server built: %s\n", ap_get_server_built());
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
8869662bb1a4078297020e94ae5e928626d877c6rederpj else if (!strnicmp("MODULES",&szcommandLine[iCommandLen],3)) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj ap_show_modules();
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener else if (!strnicmp("DIRECTIVES",&szcommandLine[iCommandLen],3)) {
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_show_directives();
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener else if (!strnicmp("SHUTDOWN",&szcommandLine[iCommandLen],3)) {
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener printf("Shutdown Requested...\n");
8869662bb1a4078297020e94ae5e928626d877c6rederpj shutdown_pending = 1;
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
8869662bb1a4078297020e94ae5e928626d877c6rederpj else if (!strnicmp("SETTINGS",&szcommandLine[iCommandLen],3)) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (show_settings) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj show_settings = 0;
8869662bb1a4078297020e94ae5e928626d877c6rederpj ClearScreen (getscreenhandle());
8869662bb1a4078297020e94ae5e928626d877c6rederpj show_server_data();
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf else {
6733d943c9e8d0f27dd077a04037e8c49eb090ffcovener show_settings = 1;
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem display_settings();
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem }
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener else {
8869662bb1a4078297020e94ae5e928626d877c6rederpj show_settings = 0;
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (strnicmp("HELP",&szcommandLine[iCommandLen],3))
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("Unknown APACHE2 command %s\n", &szcommandLine[iCommandLen]);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("Usage: APACHE2 [command] [-p <instance ID>]\n");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("Commands:\n");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("\tDIRECTIVES - Show directives\n");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("\tHELP - Display this help information\n");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("\tMODULES - Show a list of the loaded modules\n");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("\tRESTART - Reread the configuration file and restart Apache\n");
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener printf("\tSETTINGS - Show current thread status\n");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("\tSHUTDOWN - Shutdown Apache\n");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf printf("\tVERSION - Display the server version information\n");
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* Tell NetWare we handled the command */
8869662bb1a4078297020e94ae5e928626d877c6rederpj return HANDLEDCOMMAND;
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* Tell NetWare that the command isn't mine */
8869662bb1a4078297020e94ae5e928626d877c6rederpj return NOTMYCOMMAND;
8869662bb1a4078297020e94ae5e928626d877c6rederpj}
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpjstatic int InstallConsoleHandler(void)
8869662bb1a4078297020e94ae5e928626d877c6rederpj{
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* Our command line handler interfaces the system operator
8869662bb1a4078297020e94ae5e928626d877c6rederpj with this NLM */
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj NX_WRAP_INTERFACE(CommandLineInterpreter, 2, (void*)&(ConsoleHandler.parser));
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj ConsoleHandler.rTag = AllocateResourceTag(getnlmhandle(), "Command Line Processor",
8869662bb1a4078297020e94ae5e928626d877c6rederpj ConsoleCommandSignature);
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (!ConsoleHandler.rTag)
8869662bb1a4078297020e94ae5e928626d877c6rederpj {
8869662bb1a4078297020e94ae5e928626d877c6rederpj printf("Error on allocate resource tag\n");
8869662bb1a4078297020e94ae5e928626d877c6rederpj return 1;
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem RegisterConsoleCommand(&ConsoleHandler);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* The Remove procedure unregisters the console handler */
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj return 0;
8869662bb1a4078297020e94ae5e928626d877c6rederpj}
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpjstatic void RemoveConsoleHandler(void)
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem{
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem UnRegisterConsoleCommand(&ConsoleHandler);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem NX_UNWRAP_INTERFACE(ConsoleHandler.parser);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem}
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemstatic const char *set_threads_to_start(cmd_parms *cmd, void *dummy, const char *arg)
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem{
8869662bb1a4078297020e94ae5e928626d877c6rederpj const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (err != NULL) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj return err;
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj ap_threads_to_start = atoi(arg);
8869662bb1a4078297020e94ae5e928626d877c6rederpj return NULL;
8869662bb1a4078297020e94ae5e928626d877c6rederpj}
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpjstatic const char *set_min_free_threads(cmd_parms *cmd, void *dummy, const char *arg)
8869662bb1a4078297020e94ae5e928626d877c6rederpj{
8869662bb1a4078297020e94ae5e928626d877c6rederpj const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (err != NULL) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj return err;
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpj ap_threads_min_free = atoi(arg);
8869662bb1a4078297020e94ae5e928626d877c6rederpj return NULL;
8869662bb1a4078297020e94ae5e928626d877c6rederpj}
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpjstatic const char *set_max_free_threads(cmd_parms *cmd, void *dummy, const char *arg)
8869662bb1a4078297020e94ae5e928626d877c6rederpj{
8869662bb1a4078297020e94ae5e928626d877c6rederpj const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (err != NULL) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj return err;
342377e75b69a70c16175cce7f694472f9f8a6adjailletc }
342377e75b69a70c16175cce7f694472f9f8a6adjailletc
8869662bb1a4078297020e94ae5e928626d877c6rederpj ap_threads_max_free = atoi(arg);
8869662bb1a4078297020e94ae5e928626d877c6rederpj return NULL;
8869662bb1a4078297020e94ae5e928626d877c6rederpj}
8869662bb1a4078297020e94ae5e928626d877c6rederpj
8869662bb1a4078297020e94ae5e928626d877c6rederpjstatic const char *set_thread_limit (cmd_parms *cmd, void *dummy, const char *arg)
8869662bb1a4078297020e94ae5e928626d877c6rederpj{
8869662bb1a4078297020e94ae5e928626d877c6rederpj const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
8869662bb1a4078297020e94ae5e928626d877c6rederpj if (err != NULL) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj return err;
8869662bb1a4078297020e94ae5e928626d877c6rederpj }
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem ap_threads_limit = atoi(arg);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem return NULL;
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem}
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemstatic const command_rec netware_mpm_cmds[] = {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemLISTEN_COMMANDS,
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpjAP_INIT_TAKE1("StartThreads", set_threads_to_start, NULL, RSRC_CONF,
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj "Number of worker threads launched at server startup"),
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemAP_INIT_TAKE1("MinSpareThreads", set_min_free_threads, NULL, RSRC_CONF,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "Minimum number of idle threads, to handle request spikes"),
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemAP_INIT_TAKE1("MaxSpareThreads", set_max_free_threads, NULL, RSRC_CONF,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "Maximum number of idle threads"),
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemAP_INIT_TAKE1("MaxThreads", set_thread_limit, NULL, RSRC_CONF,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "Maximum number of worker threads alive at the same time"),
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem{ NULL }
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem};
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemAP_DECLARE_MODULE(mpm_netware) = {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem MPM20_MODULE_STUFF,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem netware_rewrite_args, /* hook to run before apache parses args */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem NULL, /* create per-directory config structure */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem NULL, /* merge per-directory config structures */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem NULL, /* create per-server config structure */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem NULL, /* merge per-server config structures */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem netware_mpm_cmds, /* command apr_table_t */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem netware_mpm_hooks, /* register hooks */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem};
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem