dexter.c revision a72d21c8fa26402986e82b0caa0b14d1ca36ad21
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Copyright (c) 2000 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * are met:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * <http://www.apache.org/>.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Portions of this software are based upon public domain software
f4c310fd2555c6faca1f980f00b161eadb089023gstein * originally written at the National Center for Supercomputing Applications,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * University of Illinois, Urbana-Champaign.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define CORE_PRIVATE
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_portable.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_file_io.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "httpd.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_main.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_log.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_config.h" /* for read_config */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_core.h" /* for get_remote_host */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_connection.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_mpm.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "unixd.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "mpm_common.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "iol_socket.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_listen.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "mpm_default.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "mpm.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "scoreboard.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_UNISTD_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <unistd.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <poll.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_SYS_SOCKET_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <sys/socket.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_NETINET_TCP_H
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <netinet/tcp.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <pthread.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <signal.h>
8a46775d163c06a8c51d1b0a3f2edfde945cb1d8stoddard
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Actual definitions of config globals
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic int threads_to_start = 0; /* Worker threads per child */
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic int min_spare_threads = 0;
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic int max_spare_threads = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int max_threads = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int max_requests_per_child = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *ap_pid_fname=NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_VAR_EXPORT const char *ap_scoreboard_fname=NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int num_daemons=0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int workers_may_exit = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int requests_this_child;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int num_listenfds = 0;
9f18c80269be35c0b5653e84b0db0a24044722c4gsteinstatic ap_socket_t **listenfds;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstruct ap_ctable ap_child_table[HARD_SERVER_LIMIT];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The max child slot ever assigned, preserved across restarts. Necessary
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * to deal with NumServers changes across SIGWINCH restarts. We use this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * value to optimize routines that have to scan the entire child table.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX - It might not be worth keeping this code in. There aren't very
f4c310fd2555c6faca1f980f00b161eadb089023gstein * many child processes in this MPM.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
b47464a901075041e800be2de098a603923fa4f9gsteinint ap_max_daemons_limit = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic char ap_coredump_dir[MAX_STRING_LEN];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_file_t *pipe_of_death_in = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_file_t *pipe_of_death_out = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic pthread_mutex_t pipe_of_death_mutex;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* *Non*-shared http_main globals... */
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gsteinserver_rec *ap_server_conf;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein/* one_process --- debugging mode variable; can be set from the command line
f4c310fd2555c6faca1f980f00b161eadb089023gstein * with the -X flag. If set, this gets you the child_main loop running
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in the process which originally started up (no detach, no make_child),
f4c310fd2555c6faca1f980f00b161eadb089023gstein * which is a pretty nice debugging environment. (You'll get a SIGHUP
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * early in standalone_main; just continue through. This is the server
f4c310fd2555c6faca1f980f00b161eadb089023gstein * trying to kill off any child processes which it might have lying
f4c310fd2555c6faca1f980f00b161eadb089023gstein * around --- Apache doesn't keep track of their pids, it just sends
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * SIGHUP to the process group, ignoring it in the root process.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Continue through and you'll be fine.).
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int one_process = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
b47464a901075041e800be2de098a603923fa4f9gstein#ifdef DEBUG_SIGSTOP
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint raise_sigstop_flags;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_pool_t *pconf; /* Pool for config stuff */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic ap_pool_t *pchild; /* Pool for httpd child stuff */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_pool_t *thread_pool_parent; /* Parent of per-thread pools */
b47464a901075041e800be2de098a603923fa4f9gsteinstatic pthread_mutex_t thread_pool_parent_mutex;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
b47464a901075041e800be2de098a603923fa4f9gsteinstatic int child_num;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int my_pid; /* Linux getpid() doesn't work except in main thread. Use
f4c310fd2555c6faca1f980f00b161eadb089023gstein this instead */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* Keep track of the number of worker threads currently active */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int worker_thread_count;
b47464a901075041e800be2de098a603923fa4f9gsteinstatic pthread_mutex_t worker_thread_count_mutex;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int worker_thread_free_ids[HARD_THREAD_LIMIT];
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic pthread_attr_t worker_thread_attr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Keep track of the number of idle worker threads */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int idle_thread_count;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic pthread_mutex_t idle_thread_count_mutex;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Locks for accept serialization */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef NO_SERIALIZED_ACCEPT
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define SAFE_ACCEPT(stmt) APR_SUCCESS
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#else
de18a9e85398b9c79c422f578633ed56c2747bbbgstein#define SAFE_ACCEPT(stmt) (stmt)
de18a9e85398b9c79c422f578633ed56c2747bbbgsteinstatic ap_lock_t *process_accept_mutex;
de18a9e85398b9c79c422f578633ed56c2747bbbgstein#endif /* NO_SERIALIZED_ACCEPT */
de18a9e85398b9c79c422f578633ed56c2747bbbgsteinstatic const char *lock_fname;
de18a9e85398b9c79c422f578633ed56c2747bbbgsteinstatic pthread_mutex_t thread_accept_mutex = PTHREAD_MUTEX_INITIALIZER;
de18a9e85398b9c79c422f578633ed56c2747bbbgstein
de18a9e85398b9c79c422f578633ed56c2747bbbgsteinAPI_EXPORT(const server_rec *) ap_get_server_conf(void)
de18a9e85398b9c79c422f578633ed56c2747bbbgstein{
de18a9e85398b9c79c422f578633ed56c2747bbbgstein return (ap_server_conf);
de18a9e85398b9c79c422f578633ed56c2747bbbgstein}
de18a9e85398b9c79c422f578633ed56c2747bbbgstein
de18a9e85398b9c79c422f578633ed56c2747bbbgsteinAPI_EXPORT(int) ap_get_max_daemons(void)
de18a9e85398b9c79c422f578633ed56c2747bbbgstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return ap_max_daemons_limit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* a clean exit from a child with proper cleanup */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void clean_child_exit(int code)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (pchild) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_destroy_pool(pchild);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm exit(code);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle all varieties of core dumping signals */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void sig_coredump(int sig)
de18a9e85398b9c79c422f578633ed56c2747bbbgstein{
de18a9e85398b9c79c422f578633ed56c2747bbbgstein chdir(ap_coredump_dir);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ap_signal(sig, SIG_DFL);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein kill(getpid(), sig);
000397350b42c6266351bd618fa07df929fa7c79gstein /* At this point we've got sig blocked, because we're still inside
000397350b42c6266351bd618fa07df929fa7c79gstein * the signal handler. When we leave the signal handler it will
000397350b42c6266351bd618fa07df929fa7c79gstein * be unblocked, and we'll take the signal... and coredump or whatever
000397350b42c6266351bd618fa07df929fa7c79gstein * is appropriate for this particular Unix. In addition the parent
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * will see the real signal we received -- whereas if we called
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * abort() here, the parent would only see SIGABRT.
000397350b42c6266351bd618fa07df929fa7c79gstein */
000397350b42c6266351bd618fa07df929fa7c79gstein}
000397350b42c6266351bd618fa07df929fa7c79gstein
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic void just_die(int sig)
000397350b42c6266351bd618fa07df929fa7c79gstein{
000397350b42c6266351bd618fa07df929fa7c79gstein clean_child_exit(0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Connection structures and accounting...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* volatile just in case */
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowestatic int volatile shutdown_pending;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int volatile restart_pending;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int volatile is_graceful;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * ap_start_shutdown() and ap_start_restart(), below, are a first stab at
f4c310fd2555c6faca1f980f00b161eadb089023gstein * functions to initiate shutdown or restart without relying on signals.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Previously this was initiated in sig_term() and restart() signal handlers,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * but we want to be able to start a shutdown/restart from other sources --
f4c310fd2555c6faca1f980f00b161eadb089023gstein * e.g. on Win32, from the service manager. Now the service manager can
f4c310fd2555c6faca1f980f00b161eadb089023gstein * call ap_start_shutdown() or ap_start_restart() as appropiate. Note that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * these functions can also be called by the child processes, since global
f4c310fd2555c6faca1f980f00b161eadb089023gstein * variables are no longer used to pass on the required action to the parent.
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * These should only be called from the parent process itself, since the
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein * parent process will use the shutdown_pending and restart_pending variables
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to determine whether to shutdown or restart. The child process should
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein * call signal_parent() directly to tell the parent to die -- this will
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * cause neither of those variable to be set, which the parent will
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * assume means something serious is wrong (which it will be, for the
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein * child to force an exit) and so do an exit anyway.
9f18c80269be35c0b5653e84b0db0a24044722c4gstein */
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gsteinvoid ap_start_shutdown(void)
709df1e1c2e1710570f8cb4209497e88662829c3gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (shutdown_pending == 1) {
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein /* Um, is this _probably_ not an error, if the user has
709df1e1c2e1710570f8cb4209497e88662829c3gstein * tried to do a shutdown twice quickly, so we won't
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein * worry about reporting it.
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein }
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein shutdown_pending = 1;
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein}
709df1e1c2e1710570f8cb4209497e88662829c3gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* do a graceful restart if graceful == 1 */
709df1e1c2e1710570f8cb4209497e88662829c3gsteinvoid ap_start_restart(int graceful)
709df1e1c2e1710570f8cb4209497e88662829c3gstein{
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (restart_pending == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Probably not an error - don't bother reporting it */
7281ea331999debdc337b02ce37a3169e0e033a2gstein return;
7281ea331999debdc337b02ce37a3169e0e033a2gstein }
7281ea331999debdc337b02ce37a3169e0e033a2gstein restart_pending = 1;
7281ea331999debdc337b02ce37a3169e0e033a2gstein is_graceful = graceful;
7281ea331999debdc337b02ce37a3169e0e033a2gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic void sig_term(int sig)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
000397350b42c6266351bd618fa07df929fa7c79gstein ap_start_shutdown();
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void restart(int sig)
000397350b42c6266351bd618fa07df929fa7c79gstein{
9f18c80269be35c0b5653e84b0db0a24044722c4gstein#ifndef WIN32
000397350b42c6266351bd618fa07df929fa7c79gstein ap_start_restart(sig == SIGWINCH);
000397350b42c6266351bd618fa07df929fa7c79gstein#else
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ap_start_restart(1);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein#endif
000397350b42c6266351bd618fa07df929fa7c79gstein}
000397350b42c6266351bd618fa07df929fa7c79gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gsteinstatic void set_signals(void)
000397350b42c6266351bd618fa07df929fa7c79gstein{
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein#ifndef NO_USE_SIGACTION
9f18c80269be35c0b5653e84b0db0a24044722c4gstein struct sigaction sa;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gstein sigemptyset(&sa.sa_mask);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein sa.sa_flags = 0;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gstein if (!one_process) {
9f18c80269be35c0b5653e84b0db0a24044722c4gstein sa.sa_handler = sig_coredump;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein#if defined(SA_ONESHOT)
9f18c80269be35c0b5653e84b0db0a24044722c4gstein sa.sa_flags = SA_ONESHOT;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein#elif defined(SA_RESETHAND)
9f18c80269be35c0b5653e84b0db0a24044722c4gstein sa.sa_flags = SA_RESETHAND;
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein#endif
000397350b42c6266351bd618fa07df929fa7c79gstein if (sigaction(SIGSEGV, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGSEGV)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGBUS
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGBUS, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGBUS)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABORT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGABORT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABORT)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABRT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGABRT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGABRT)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGILL
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGILL, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGILL)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_flags = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = sig_term;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGTERM, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGTERM)");
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein#ifdef SIGINT
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGINT, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGINT)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXCPU
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = SIG_DFL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGXCPU, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXCPU)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXFSZ
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = SIG_DFL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGXFSZ, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGXFSZ)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPIPE
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein sa.sa_handler = SIG_IGN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGPIPE, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGPIPE)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we want to ignore HUPs and WINCH while we're busy processing one */
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigaddset(&sa.sa_mask, SIGHUP);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigaddset(&sa.sa_mask, SIGWINCH);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sa.sa_handler = restart;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGHUP, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGHUP)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigaction(SIGWINCH, &sa, NULL) < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGWINCH)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGSEGV, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGBUS
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGBUS, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGBUS */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABORT
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGABORT, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGABORT */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGABRT
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGABRT, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGABRT */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGILL
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGILL, sig_coredump);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGILL */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXCPU
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGXCPU, SIG_DFL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGXCPU */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGXFSZ
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGXFSZ, SIG_DFL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGXFSZ */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGTERM, sig_term);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGHUP
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGHUP, restart);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGHUP */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGWINCH
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGWINCH, restart);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGWINCH */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPIPE
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGPIPE, SIG_IGN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* SIGPIPE */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void process_child_status(ap_proc_t *pid, ap_wait_t status)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Child died... if it died due to a fatal error,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we should simply bail out.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((WIFEXITED(status)) &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein WEXITSTATUS(status) == APEXIT_CHILDFATAL) {
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Child %ld returned a Fatal error... \n"
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Apache is exiting!",
f4c310fd2555c6faca1f980f00b161eadb089023gstein (long)pid->pid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (WIFSIGNALED(status)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (WTERMSIG(status)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein case SIGTERM:
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein case SIGHUP:
f4c310fd2555c6faca1f980f00b161eadb089023gstein case SIGUSR1:
f4c310fd2555c6faca1f980f00b161eadb089023gstein case SIGKILL:
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein default:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#ifdef SYS_SIGLIST
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef WCOREDUMP
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (WCOREDUMP(status)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "child pid %ld exit signal %s (%d), "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "possible coredump in %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein (long)pid->pid, (WTERMSIG(status) >= NumSIG) ? "" :
f4c310fd2555c6faca1f980f00b161eadb089023gstein SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status),
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_coredump_dir);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "child pid %ld exit signal %s (%d)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein (long)pid->pid,
f4c310fd2555c6faca1f980f00b161eadb089023gstein SYS_SIGLIST[WTERMSIG(status)], WTERMSIG(status));
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein#ifdef WCOREDUMP
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "child pid %ld exit signal %d",
f4c310fd2555c6faca1f980f00b161eadb089023gstein (long)pid->pid, WTERMSIG(status));
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int setup_listeners(server_rec *s)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int num_listeners = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_listen_open(s->process, s->port)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (lr = ap_listeners; lr; lr = lr->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein num_listeners++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return num_listeners;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
d839a9822ee53ce00da24c15f2d9fe054233d342gstein
d839a9822ee53ce00da24c15f2d9fe054233d342gstein/*****************************************************************
d839a9822ee53ce00da24c15f2d9fe054233d342gstein * Here follows a long bunch of generic server bookkeeping stuff...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
d839a9822ee53ce00da24c15f2d9fe054233d342gstein
d839a9822ee53ce00da24c15f2d9fe054233d342gstein#if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void sock_disable_nagle(int s)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The Nagle algorithm says that we should delay sending partial
f4c310fd2555c6faca1f980f00b161eadb089023gstein * packets in hopes of getting more data. We don't want to do
f4c310fd2555c6faca1f980f00b161eadb089023gstein * this; we are not telnet. There are bad interactions between
f4c310fd2555c6faca1f980f00b161eadb089023gstein * persistent connections and Nagle's algorithm that have very severe
f4c310fd2555c6faca1f980f00b161eadb089023gstein * performance penalties. (Failing to disable Nagle is not much of a
f4c310fd2555c6faca1f980f00b161eadb089023gstein * problem with simple HTTP.)
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * In spite of these problems, failure here is not a shooting offense.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein int just_say_no = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &just_say_no,
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(int)) < 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "setsockopt: (TCP_NODELAY)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define sock_disable_nagle(s) /* NOOP */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_graceful_stop_signalled(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX - Does this really work? - Manoj */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return is_graceful;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Child process main loop.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void process_socket(ap_pool_t *p, ap_socket_t *sock, long conn_id)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein BUFF *conn_io;
f4c310fd2555c6faca1f980f00b161eadb089023gstein conn_rec *current_conn;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_iol *iol;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int csd;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((rv = ap_get_os_sock(&csd, sock)) != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "ap_get_os_sock");
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (csd >= FD_SETSIZE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "new file descriptor %d is too large; you probably need "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "to rebuild Apache with a larger FD_SETSIZE "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "(currently %d)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein csd, FD_SETSIZE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_close_socket(sock);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein sock_disable_nagle(csd);
f4c310fd2555c6faca1f980f00b161eadb089023gstein iol = ap_iol_attach_socket(sock);
f4c310fd2555c6faca1f980f00b161eadb089023gstein conn_io = ap_bcreate(p, B_RDWR);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_bpush_iol(conn_io, iol);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein current_conn = ap_new_apr_connection(p, ap_server_conf, conn_io, sock,
f4c310fd2555c6faca1f980f00b161eadb089023gstein conn_id);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_process_connection(current_conn);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_lingering_close(current_conn);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void *worker_thread(void *);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Starts a thread as long as we're below max_threads */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int start_thread(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_t thread;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_lock(&worker_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (worker_thread_count < max_threads) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (pthread_create(&thread, &worker_thread_attr, worker_thread,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &worker_thread_free_ids[worker_thread_count])) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "pthread_create: unable to create worker thread");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* In case system resources are maxxed out, we don't want
f4c310fd2555c6faca1f980f00b161eadb089023gstein Apache running away with the CPU trying to fork over and
f4c310fd2555c6faca1f980f00b161eadb089023gstein over and over again if we exit. */
50bd75672ef114fb839dd9643c192b432fdf344cgstein sleep(10);
50bd75672ef114fb839dd9643c192b432fdf344cgstein workers_may_exit = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&worker_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
50bd75672ef114fb839dd9643c192b432fdf344cgstein else {
50bd75672ef114fb839dd9643c192b432fdf344cgstein worker_thread_count++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein static int reported = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!reported) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "server reached MaxThreadsPerChild setting, consider raising the"
f4c310fd2555c6faca1f980f00b161eadb089023gstein " MaxThreadsPerChild or NumServers settings");
f4c310fd2555c6faca1f980f00b161eadb089023gstein reported = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein pthread_mutex_unlock(&worker_thread_count_mutex);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&worker_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* Sets workers_may_exit if we received a character on the pipe_of_death */
50bd75672ef114fb839dd9643c192b432fdf344cgsteinstatic void check_pipe_of_death(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_lock(&pipe_of_death_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!workers_may_exit) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int ret;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char pipe_read_char;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_ssize_t n = 1;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein ret = ap_recv(listenfds[0], &pipe_read_char, &n);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_canonical_error(ret) == APR_EAGAIN) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* It lost the lottery. It must continue to suffer
f4c310fd2555c6faca1f980f00b161eadb089023gstein * through a life of servitude. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* It won the lottery (or something else is very
f4c310fd2555c6faca1f980f00b161eadb089023gstein * wrong). Embrace death with open arms. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein workers_may_exit = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&pipe_of_death_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* idle_thread_count should be incremented before starting a worker_thread */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void *worker_thread(void *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_socket_t *csd = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pool_t *tpool; /* Pool for this thread */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pool_t *ptrans; /* Pool for per-transaction stuff */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_socket_t *sd = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int srv;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int curr_pollfd, last_pollfd = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int thread_just_started = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int thread_num = *((int *) arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein long conn_id = child_num * HARD_THREAD_LIMIT + thread_num;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pollfd_t *pollset;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int n;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_lock(&thread_pool_parent_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_create_pool(&tpool, thread_pool_parent);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&thread_pool_parent_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_create_pool(&ptrans, tpool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_setup_poll(&pollset, num_listenfds+1, tpool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein for(n=0 ; n <= num_listenfds ; ++n)
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_add_poll_socket(pollset, listenfds[n], APR_POLLIN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!workers_may_exit) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein workers_may_exit |= (max_requests_per_child != 0) && (requests_this_child <= 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (workers_may_exit) break;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (!thread_just_started) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein pthread_mutex_lock(&idle_thread_count_mutex);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (idle_thread_count < max_spare_threads) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein idle_thread_count++;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein pthread_mutex_unlock(&idle_thread_count_mutex);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&idle_thread_count_mutex);
ba8574a7fe6f1c3405982bb856591b5f13fe205agstein break;
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein else {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein thread_just_started = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
ba8574a7fe6f1c3405982bb856591b5f13fe205agstein pthread_mutex_lock(&thread_accept_mutex);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (workers_may_exit) {
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein pthread_mutex_unlock(&thread_accept_mutex);
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein break;
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein }
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein if ((rv = SAFE_ACCEPT(ap_lock(process_accept_mutex)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein != APR_SUCCESS) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein "ap_lock failed. Attempting to shutdown "
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein "process gracefully.");
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein workers_may_exit = 1;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein while (!workers_may_exit) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein ap_int16_t event;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein srv = ap_poll(pollset, &n, -1);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gstein if (srv != APR_SUCCESS) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (ap_canonical_error(srv) == APR_EINTR) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein continue;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein }
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein /* ap_poll() will only return errors in catastrophic
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein * circumstances. Let's try exiting gracefully, for now. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, srv, (const server_rec *)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_get_server_conf(), "ap_poll: (listen)");
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein workers_may_exit = 1;
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (workers_may_exit) break;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein ap_get_revents(&event, listenfds[0], pollset);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (event & APR_POLLIN) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* A process got a signal on the shutdown pipe. Check if we're
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * the lucky process to die. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein check_pipe_of_death();
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (num_listenfds == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein sd = ap_listeners->sd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein goto got_fd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* find a listener */
f4c310fd2555c6faca1f980f00b161eadb089023gstein curr_pollfd = last_pollfd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein do {
f4c310fd2555c6faca1f980f00b161eadb089023gstein curr_pollfd++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (curr_pollfd > num_listenfds) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein curr_pollfd = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: Should we check for POLLERR? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_get_revents(&event, listenfds[curr_pollfd], pollset);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (event & APR_POLLIN) {
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein last_pollfd = curr_pollfd;
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein sd = listenfds[curr_pollfd];
f4c310fd2555c6faca1f980f00b161eadb089023gstein goto got_fd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein } while (curr_pollfd != last_pollfd);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein got_fd:
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!workers_may_exit) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if ((rv = ap_accept(&csd, sd, ptrans)) != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, "ap_accept");
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein }
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein if ((rv = SAFE_ACCEPT(ap_unlock(process_accept_mutex)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "ap_unlock failed. Attempting to shutdown "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "process gracefully.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein workers_may_exit = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&thread_accept_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_lock(&idle_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (idle_thread_count > min_spare_threads) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_thread_count--;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!start_thread()) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_thread_count--;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&idle_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein process_socket(ptrans, csd, conn_id);
f4c310fd2555c6faca1f980f00b161eadb089023gstein requests_this_child--;
f4c310fd2555c6faca1f980f00b161eadb089023gstein } else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((rv = SAFE_ACCEPT(ap_unlock(process_accept_mutex)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "ap_unlock failed. Attempting to shutdown "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "process gracefully.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein workers_may_exit = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein pthread_mutex_unlock(&thread_accept_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_lock(&idle_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_thread_count--;
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&idle_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_clear_pool(ptrans);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_lock(&thread_pool_parent_mutex);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein ap_destroy_pool(tpool);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein pthread_mutex_unlock(&thread_pool_parent_mutex);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein pthread_mutex_lock(&worker_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein worker_thread_count--;
f4c310fd2555c6faca1f980f00b161eadb089023gstein worker_thread_free_ids[worker_thread_count] = thread_num;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (worker_thread_count == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* All the threads have exited, now finish the shutdown process
f4c310fd2555c6faca1f980f00b161eadb089023gstein * by signalling the sigwait thread */
f4c310fd2555c6faca1f980f00b161eadb089023gstein kill(my_pid, SIGTERM);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_unlock(&worker_thread_count_mutex);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void child_main(int child_num_arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigset_t sig_mask;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int signal_received;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_rec *lr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein my_pid = getpid();
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_num = child_num_arg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_create_pool(&pchild, pconf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*stuff to do before we switch id's, so we have permissions.*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = SAFE_ACCEPT(ap_child_init_lock(&process_accept_mutex, lock_fname,
f4c310fd2555c6faca1f980f00b161eadb089023gstein pchild));
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Couldn't initialize cross-process lock in child");
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (unixd_setup_child()) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein clean_child_exit(APEXIT_CHILDFATAL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_init_hook(pchild, ap_server_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*done with init critical section */
f958dac1550254a59b45f4655138bb34dad5e76egstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* All threads should mask signals out, accoring to sigwait(2) man page */
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigfillset(&sig_mask);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SIGPROCMASK_SETS_THREAD_MASK
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sigprocmask(SIG_SETMASK, &sig_mask, NULL) != 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf, "sigprocmask");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (pthread_sigmask(SIG_SETMASK, &sig_mask, NULL) != 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "pthread_sigmask");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein requests_this_child = max_requests_per_child;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Set up the pollfd array */
f4c310fd2555c6faca1f980f00b161eadb089023gstein listenfds = ap_pcalloc(pchild, sizeof(*listenfds) * (num_listenfds + 1));
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_FILES_AS_SOCKETS
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_socket_from_file(&listenfds[0], pipe_of_death_in);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (lr = ap_listeners, i = 1; i <= num_listenfds; lr = lr->next, ++i)
f4c310fd2555c6faca1f980f00b161eadb089023gstein listenfds[i]=lr->sd;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Setup worker threads */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (threads_to_start > max_threads) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein threads_to_start = max_threads;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein idle_thread_count = threads_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein worker_thread_count = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < max_threads; i++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein worker_thread_free_ids[i] = i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_create_pool(&thread_pool_parent, pchild);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_init(&thread_pool_parent_mutex, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_init(&idle_thread_count_mutex, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_init(&worker_thread_count_mutex, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_mutex_init(&pipe_of_death_mutex, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_attr_init(&worker_thread_attr);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef PTHREAD_ATTR_SETDETACHSTATE_ARG2_ADDR
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int on = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_attr_setdetachstate(&worker_thread_attr, &on);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein pthread_attr_setdetachstate(&worker_thread_attr, PTHREAD_CREATE_DETACHED);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* We are creating worker threads right now */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i=0; i < threads_to_start; i++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* start_thread shouldn't fail here */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!start_thread()) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This thread will be the one responsible for handling signals */
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigemptyset(&sig_mask);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigaddset(&sig_mask, SIGTERM);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sigaddset(&sig_mask, SIGINT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_sigwait(&sig_mask, &signal_received);
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (signal_received) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm case SIGTERM:
f4c310fd2555c6faca1f980f00b161eadb089023gstein case SIGINT:
f4c310fd2555c6faca1f980f00b161eadb089023gstein just_die(signal_received);
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein default:
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ALERT, errno, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "received impossible signal: %d", signal_received);
f4c310fd2555c6faca1f980f00b161eadb089023gstein just_die(SIGTERM);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int make_child(server_rec *s, int slot, time_t now)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int pid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (slot + 1 > ap_max_daemons_limit) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_daemons_limit = slot + 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein set_signals();
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_table[slot].pid = getpid();
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_table[slot].status = SERVER_ALIVE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_main(slot);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((pid = fork()) == -1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, errno, s,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "fork: Unable to fork new process");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* In case system resources are maxxed out, we don't want
f4c310fd2555c6faca1f980f00b161eadb089023gstein Apache running away with the CPU trying to fork over and
f4c310fd2555c6faca1f980f00b161eadb089023gstein over and over again. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein sleep(10);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!pid) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef AIX_BIND_PROCESSOR
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* By default, AIX binds to a single processor. This bit unbinds
f4c310fd2555c6faca1f980f00b161eadb089023gstein children which will then bind to another CPU.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include <sys/processor.h>
f4c310fd2555c6faca1f980f00b161eadb089023gstein int status = bindprocessor(BINDPROCESS, (int)getpid(),
f4c310fd2555c6faca1f980f00b161eadb089023gstein PROCESSOR_CLASS_ANY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status != OK)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, errno,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf, "processor unbind failed %d", status);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein RAISE_SIGSTOP(MAKE_CHILD);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX - For an unthreaded server, a signal handler will be necessary
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGTERM, just_die);
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_main(slot);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* else */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_table[slot].pid = pid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_table[slot].status = SERVER_ALIVE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* start up a bunch of children */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int startup_children(int number_to_start)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; number_to_start && i < num_daemons; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_child_table[i].status != SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (make_child(ap_server_conf, i, 0) < 0) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein --number_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return number_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * spawn_rate is the number of children that will be spawned on the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * next maintenance cycle if there aren't enough servers. It is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
f4c310fd2555c6faca1f980f00b161eadb089023gstein * without the need to spawn.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int spawn_rate = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifndef MAX_SPAWN_RATE
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define MAX_SPAWN_RATE (32)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int hold_off_on_exponential_spawning;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
83719c22db4a6d0575bb4f7f34382d7b185a6f74gsteinstatic void perform_child_maintenance(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein time_t now = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int free_length;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int free_slots[MAX_SPAWN_RATE];
f4c310fd2555c6faca1f980f00b161eadb089023gstein int last_non_dead = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* initialize the free_list */
f4c310fd2555c6faca1f980f00b161eadb089023gstein free_length = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < num_daemons; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_child_table[i].status == SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (free_length < spawn_rate) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein free_slots[free_length] = i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++free_length;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein last_non_dead = i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (i >= ap_max_daemons_limit && free_length >= spawn_rate) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_max_daemons_limit = last_non_dead + 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (free_length > 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < free_length; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein make_child(ap_server_conf, free_slots[i], now);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* the next time around we want to spawn twice as many if this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * wasn't good enough, but not if we've just done a graceful
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (hold_off_on_exponential_spawning) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein --hold_off_on_exponential_spawning;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (spawn_rate < MAX_SPAWN_RATE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein spawn_rate *= 2;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein spawn_rate = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void server_main_loop(int remaining_children_to_start)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int child_slot;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_wait_t status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_proc_t pid;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!restart_pending && !shutdown_pending) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_wait_or_timeout(&status, &pid, pconf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (pid.pid != -1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein process_child_status(&pid, status);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* non-fatal death... note that it's gone in the child table and
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * clean out the status table. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_slot = -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < ap_max_daemons_limit; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_child_table[i].pid == pid.pid) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int j;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein child_slot = i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (j = 0; j < HARD_THREAD_LIMIT; j++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_dexter_force_reset_connection_status(i * HARD_THREAD_LIMIT + j);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (child_slot >= 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_table[child_slot].status = SERVER_DEAD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (remaining_children_to_start
f4c310fd2555c6faca1f980f00b161eadb089023gstein && child_slot < num_daemons) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* we're still doing a 1-for-1 replacement of dead
f4c310fd2555c6faca1f980f00b161eadb089023gstein * children with new children
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein make_child(ap_server_conf, child_slot, time(NULL));
f4c310fd2555c6faca1f980f00b161eadb089023gstein --remaining_children_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef APR_HAS_OTHER_CHILD
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (ap_reap_other_child(&pid, status) == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* handled */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (is_graceful) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Great, we've probably just lost a slot in the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * child table. Somehow we don't know about this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * child.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "long lost child came home! (pid %ld)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein (long)pid.pid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Don't perform idle maintenance when a child dies,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * only do it when there's a timeout. Remember only a
f4c310fd2555c6faca1f980f00b161eadb089023gstein * finite number of children can die, and it's pretty
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pathological for a lot to die suddenly.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (remaining_children_to_start) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we hit a 1 second timeout in which none of the previous
f4c310fd2555c6faca1f980f00b161eadb089023gstein * generation of children needed to be reaped... so assume
f4c310fd2555c6faca1f980f00b161eadb089023gstein * they're all done, and pick up the slack if any is left.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein remaining_children_to_start = \
f4c310fd2555c6faca1f980f00b161eadb089023gstein startup_children(remaining_children_to_start);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* In any event we really shouldn't do the code below because
f4c310fd2555c6faca1f980f00b161eadb089023gstein * few of the servers we just started are in the IDLE state
f4c310fd2555c6faca1f980f00b161eadb089023gstein * yet, so we'd mistakenly create an extra server.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein perform_child_maintenance();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int remaining_children_to_start;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_ssize_t one = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein pconf = _pconf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf = s;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((rv = ap_create_pipe(&pipe_of_death_in, &pipe_of_death_out, pconf))
f4c310fd2555c6faca1f980f00b161eadb089023gstein != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, rv,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (const server_rec*) ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "ap_create_pipe (pipe_of_death)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein exit(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((rv = ap_set_pipe_timeout(pipe_of_death_in, 0)) != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR, rv,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein (const server_rec*) ap_server_conf,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein "ap_set_pipe_timeout (pipe_of_death)");
f4c310fd2555c6faca1f980f00b161eadb089023gstein exit(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf = s;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((num_listenfds = setup_listeners(ap_server_conf)) < 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, 0, s,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "no listening sockets available, shutting down");
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_pid(pconf, ap_pid_fname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Initialize cross-process accept lock */
f4c310fd2555c6faca1f980f00b161eadb089023gstein lock_fname = ap_psprintf(_pconf, "%s.%lu",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_root_relative(_pconf, lock_fname),
f4c310fd2555c6faca1f980f00b161eadb089023gstein my_pid);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = SAFE_ACCEPT(ap_create_lock(&process_accept_mutex, APR_MUTEX,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_CROSS_PROCESS, lock_fname, _pconf));
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Couldn't create cross-process lock");
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein reinit_scoreboard(pconf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Initialize the child table */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < HARD_SERVER_LIMIT; i++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_table[i].status = SERVER_DEAD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein set_signals();
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If we're doing a graceful_restart then we're going to see a lot
f4c310fd2555c6faca1f980f00b161eadb089023gstein * of children exiting immediately when we get into the main loop
f4c310fd2555c6faca1f980f00b161eadb089023gstein * below (because we just sent them SIGWINCH). This happens pretty
f4c310fd2555c6faca1f980f00b161eadb089023gstein * rapidly... and for each one that exits we'll start a new one until
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we reach at least daemons_min_free. But we may be permitted to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * start more than that, so we'll just keep track of how many we're
f4c310fd2555c6faca1f980f00b161eadb089023gstein * supposed to start up without the 1 second penalty between each fork.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein remaining_children_to_start = num_daemons;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein remaining_children_to_start = \
f4c310fd2555c6faca1f980f00b161eadb089023gstein startup_children(remaining_children_to_start);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* give the system some time to recover before kicking into
7281ea331999debdc337b02ce37a3169e0e033a2gstein * exponential mode */
f4c310fd2555c6faca1f980f00b161eadb089023gstein hold_off_on_exponential_spawning = 10;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe "%s configured -- resuming normal operations",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_get_server_version());
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Server built: %s", ap_get_server_built());
f4c310fd2555c6faca1f980f00b161eadb089023gstein restart_pending = shutdown_pending = 0;
00f73f5096966f34c7db15562e5d2e1233eb4571gstein
00f73f5096966f34c7db15562e5d2e1233eb4571gstein server_main_loop(remaining_children_to_start);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (shutdown_pending) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Time to gracefully shut down:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Kill child processes, tell them to call child_exit, etc...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein if (unixd_killpg(getpgrp(), SIGTERM) < 0) {
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "killpg SIGTERM");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_reclaim_child_processes(1); /* Start with SIGTERM */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* cleanup pid file on normal shutdown */
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein const char *pidfile = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein pidfile = ap_server_root_relative (pconf, ap_pid_fname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ( pidfile != NULL && unlink(pidfile) == 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "removed PID file %s (pid=%ld)",
f4c310fd2555c6faca1f980f00b161eadb089023gstein pidfile, (long)getpid());
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf, "caught SIGTERM, shutting down");
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we've been told to restart */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_signal(SIGHUP, SIG_IGN);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* not worth thinking about */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (is_graceful) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char char_of_death = '!';
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "SIGWINCH received. Doing graceful restart");
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This is mostly for debugging... so that we know what is still
f4c310fd2555c6faca1f980f00b161eadb089023gstein * gracefully dealing with existing request.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < num_daemons; ++i) {
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein if (ap_child_table[i].status != SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_child_table[i].status = SERVER_DYING;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* give the children the signal to die */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < num_daemons;) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((rv = ap_write(pipe_of_death_out, &char_of_death, &one)) != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_canonical_error(rv) == APR_EINTR) continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "write pipe_of_death");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein i++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Kill 'em all. Since the child acts the same on the parents SIGTERM
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and a SIGHUP, we may as well use the same signal, because some user
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pthreads are stealing signals from us left and right.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (unixd_killpg(getpgrp(), SIGTERM) < 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "killpg SIGTERM");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_reclaim_child_processes(1); /* Start with SIGTERM */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_server_conf, "SIGHUP received. Attempting to restart");
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void dexter_pre_config(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein static int restart_num = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein one_process = !!getenv("ONE_PROCESS");
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* sigh, want this only the second time around */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (restart_num++ == 1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein is_graceful = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!one_process) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_detach();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein my_pid = getpid();
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein unixd_pre_config();
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_listen_pre_config();
f4c310fd2555c6faca1f980f00b161eadb089023gstein num_daemons = DEFAULT_NUM_DAEMON;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm threads_to_start = DEFAULT_START_THREAD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein min_spare_threads = DEFAULT_MIN_SPARE_THREAD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein max_spare_threads = DEFAULT_MAX_SPARE_THREAD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein max_threads = HARD_THREAD_LIMIT;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_pid_fname = DEFAULT_PIDLOG;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_fname = DEFAULT_SCOREBOARD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein lock_fname = DEFAULT_LOCKFILE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_dexter_set_maintain_connection_status(1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void dexter_hooks(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein INIT_SIGLIST()
f4c310fd2555c6faca1f980f00b161eadb089023gstein one_process = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_hook_pre_config(dexter_pre_config, NULL, NULL, AP_HOOK_MIDDLE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (cmd->server->is_virtual) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return "PidFile directive not allowed in <VirtualHost>";
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_pid_fname = arg;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_scoreboard_fname = arg;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein lock_fname = arg;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_num_daemons (cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein num_daemons = atoi(arg);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (num_daemons > HARD_SERVER_LIMIT) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "WARNING: NumServers of %d exceeds compile time limit "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "of %d servers,", num_daemons, HARD_SERVER_LIMIT);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein " lowering NumServers to %d. To increase, please "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "see the", HARD_SERVER_LIMIT);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein " HARD_SERVER_LIMIT define in %s.",
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein AP_MPM_HARD_LIMITS_FILE);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein num_daemons = HARD_SERVER_LIMIT;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein else if (num_daemons < 1) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "WARNING: Require NumServers > 0, setting to 1");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein num_daemons = 1;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_threads_to_start (cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein threads_to_start = atoi(arg);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (threads_to_start > HARD_THREAD_LIMIT) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "WARNING: StartThreads of %d exceeds compile time"
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein " limit of %d threads,", threads_to_start,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein HARD_THREAD_LIMIT);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein " lowering StartThreads to %d. To increase, please"
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein " see the", HARD_THREAD_LIMIT);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein " HARD_THREAD_LIMIT define in %s.",
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein AP_MPM_HARD_LIMITS_FILE);
bbba27074551817d7c6a606c4362965c26a0777egstein }
bbba27074551817d7c6a606c4362965c26a0777egstein else if (threads_to_start < 1) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "WARNING: Require StartThreads > 0, setting to 1");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein threads_to_start = 1;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
bbba27074551817d7c6a606c4362965c26a0777egstein return NULL;
bbba27074551817d7c6a606c4362965c26a0777egstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_min_spare_threads(cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein min_spare_threads = atoi(arg);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (min_spare_threads <= 0) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "WARNING: detected MinSpareThreads set to non-positive.");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Resetting to 1 to avoid almost certain Apache failure.");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Please read the documentation.");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein min_spare_threads = 1;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_max_spare_threads(cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein max_spare_threads = atoi(arg);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (max_spare_threads >= HARD_THREAD_LIMIT) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "WARNING: detected MinSpareThreads set higher than");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "HARD_THREAD_LIMIT. Resetting to %d", HARD_THREAD_LIMIT);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein max_spare_threads = HARD_THREAD_LIMIT;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
bbba27074551817d7c6a606c4362965c26a0777egstein}
bbba27074551817d7c6a606c4362965c26a0777egstein
bbba27074551817d7c6a606c4362965c26a0777egsteinstatic const char *set_max_threads(cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein max_threads = atoi(arg);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (max_threads > HARD_THREAD_LIMIT) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "WARNING: detected MaxThreadsPerChild set higher than");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "HARD_THREAD_LIMIT. Resetting to %d", HARD_THREAD_LIMIT);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein max_threads = HARD_THREAD_LIMIT;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_max_requests(cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein max_requests_per_child = atoi(arg);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_maintain_connection_status(cmd_parms *cmd,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein void *dummy, int arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_dexter_set_maintain_connection_status(arg != 0);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const char *set_coredumpdir (cmd_parms *cmd, void *dummy, const char *arg)
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{
bbba27074551817d7c6a606c4362965c26a0777egstein ap_finfo_t finfo;
bbba27074551817d7c6a606c4362965c26a0777egstein const char *fname;
bbba27074551817d7c6a606c4362965c26a0777egstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
bbba27074551817d7c6a606c4362965c26a0777egstein if (err != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return err;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein fname = ap_server_root_relative(cmd->pool, arg);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if ((ap_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) ||
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein (finfo.filetype != APR_DIR)) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein " does not exist or is not a directory", NULL);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir));
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein return NULL;
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein}
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic const command_rec dexter_cmds[] = {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinUNIX_DAEMON_COMMANDS
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinLISTEN_COMMANDS
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "A file for logging the server process ID"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "A file for Apache to maintain runtime process management information"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "The lockfile used when Apache needs to lock the accept() call"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("NumServers", set_num_daemons, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Number of children alive at the same time"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("StartThreads", set_threads_to_start, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Number of threads each child creates"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("MinSpareThreads", set_min_spare_threads, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Minimum number of idle threads per child, to handle request spikes"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("MaxSpareThreads", set_max_spare_threads, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Maximum number of idle threads per child"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("MaxThreadsPerChild", set_max_threads, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Maximum number of threads per child"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Maximum number of requests a particular child serves before dying."),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_FLAG("ConnectionStatus", set_maintain_connection_status, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "Whether or not to maintain status information on current connections"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinAP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "The location of the directory Apache changes to before dumping core"),
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein{ NULL }
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein};
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinmodule MODULE_VAR_EXPORT mpm_dexter_module = {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein MPM20_MODULE_STUFF,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein NULL, /* hook to run before apache parses args */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein NULL, /* create per-directory config structure */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein NULL, /* merge per-directory config structures */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein NULL, /* create per-server config structure */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein NULL, /* merge per-server config structures */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein dexter_cmds, /* command ap_table_t */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein NULL, /* handlers */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein dexter_hooks /* register_hooks */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein};
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein