mpm_winnt.c revision 5bfaaf573bacb45c1cf290ce85ecc676587e8a64
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef WIN32
#include "httpd.h"
#include "http_main.h"
#include "http_log.h"
#include "http_config.h" /* for read_config */
#include "http_core.h" /* for get_remote_host */
#include "http_connection.h"
#include "apr_portable.h"
#include "apr_thread_proc.h"
#include "apr_getopt.h"
#include "apr_strings.h"
#include "apr_lib.h"
#include "apr_shm.h"
#include "apr_thread_mutex.h"
#include "ap_mpm.h"
#include "apr_general.h"
#include "ap_config.h"
#include "ap_listen.h"
#include "mpm_default.h"
#include "mpm_winnt.h"
#include "mpm_common.h"
#include <malloc.h>
#include "apr_atomic.h"
#include "scoreboard.h"
#ifdef __WATCOMC__
#endif
#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION /* missing on MinGW */
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
#endif
/* Because ap_setup_listeners() is skipped in the child, any merging
* of [::]:80 and 0.0.0.0:80 for AP_ENABLE_V4_MAPPED in the parent
* won't have taken place in the child, so the child will expect to
* read two sockets for "Listen 80" but the parent will send only
* one.
*/
#ifdef AP_ENABLE_V4_MAPPED
#endif
/* scoreboard.c does the heavy lifting; all we do is create the child
* score by moving a handle down the pipe into the child's stdin.
*/
extern apr_shm_t *ap_scoreboard_shm;
/* my_generation is returned to the scoreboard code */
static volatile ap_generation_t my_generation=0;
/* Definitions of WINNT MPM specific config globals */
static int one_process = 0;
static char const* signal_arg = NULL;
/* set by child_main to STACK_SIZE_PARAM_IS_A_RESERVATION for NT >= 5.1 (XP/2003) */
static DWORD parent_pid;
/* used by parent to signal the child to start and exit */
int ap_threads_per_child = 0;
static int thread_limit = 0;
static int first_thread_limit = 0;
int winnt_mpm_state = AP_MPMQ_STARTING;
/* shared by service.c as global, although
* perhaps it should be private.
*/
/* definitions from child.c */
/* Only one of these, the pipe from our parent, meant only for
* one child worker's consumption (not to be inherited!)
* XXX: decorate this name for the trunk branch, was left simplified
* only to make the 2.2 patch trivial to read.
*/
/*
* Command processors
*/
{
return err;
}
return NULL;
}
{
return err;
}
return NULL;
}
static const command_rec winnt_cmds[] = {
"Number of threads each child creates" ),
"Maximum worker threads in a server for this run of Apache"),
{ NULL }
};
{
}
static void winnt_note_child_killed(int slot)
{
}
/*
* Signalling Apache on NT.
*
* Under Unix, Apache can be told to shutdown or restart by sending various
* signals (HUP, USR, TERM). On NT we don't have easy access to signals, so
* we use "events" instead. The parent apache process goes into a loop
* where it waits forever for a set of events. Two of those events are
* called
*
* apPID_shutdown
* apPID_restart
*
* (where PID is the PID of the apache parent process). When one of these
* is signalled, the Apache parent performs the appropriate action. The events
* can become signalled through internal Apache methods (e.g. if the child
* finds a fatal error and needs to kill its parent), via the service
* control manager (the control thread will signal the shutdown event when
* requested to stop the Apache service), from the -k Apache command line,
* or from any external program which finds the Apache PID from the
* httpd.pid file.
*
* The signal_parent() function, below, is used to signal one of these events.
* It can be called by any child or parent process, since it does not
* rely on global variables.
*
* On entry, type gives the event to signal. 0 means shutdown, 1 means
* graceful restart.
*/
/*
* Initialise the signal names, in the global variables signal_name_prefix,
* signal_restart_name and signal_shutdown_name.
*/
void setup_signal_names(char *prefix)
{
"%s_shutdown", signal_name_prefix);
"%s_restart", signal_name_prefix);
}
{
HANDLE e;
char *signal_name;
if (parent_pid == my_pid) {
switch(type) {
case SIGNAL_PARENT_SHUTDOWN:
{
break;
}
/* This MPM supports only graceful restarts right now */
case SIGNAL_PARENT_RESTART:
{
break;
}
}
return;
}
switch(type) {
case SIGNAL_PARENT_SHUTDOWN:
{
break;
}
/* This MPM supports only graceful restarts right now */
case SIGNAL_PARENT_RESTART:
{
break;
}
default:
return;
}
if (!e) {
/* Um, problem, can't signal the parent, which means we can't
* signal ourselves to die. Ignore for now...
*/
"OpenEvent on %s event", signal_name);
return;
}
if (SetEvent(e) == 0) {
/* Same problem as above */
"SetEvent on %s event", signal_name);
CloseHandle(e);
return;
}
CloseHandle(e);
}
/*
* Passed the following handles [in sync with send_handles_to_child()]
*
* ready event [signal the parent immediately, then close]
* exit event [save to poll later]
* start mutex [signal from the parent to begin accept()]
* scoreboard shm handle [to recreate the ap_scoreboard]
*/
{
void *sb_shared;
/* *** We now do this was back in winnt_rewrite_args
* pipe = GetStdHandle(STD_INPUT_HANDLE);
*/
"Child: Unable to retrieve the ready event from the parent");
}
"Child: Unable to retrieve the exit event from the parent");
}
"Child: Unable to retrieve the start_mutex from the parent");
}
!= APR_SUCCESS) {
"Child: Unable to access the start_mutex from the parent");
}
"Child: Unable to retrieve the scoreboard from the parent");
}
*scoreboard_shm = NULL;
!= APR_SUCCESS) {
"Child: Unable to access the scoreboard from the parent");
}
"Child: Unable to reopen the scoreboard from the parent");
}
/* We must 'initialize' the scoreboard to relink all the
* process-local pointer arrays into the shared memory block.
*/
"Child: Retrieved our scoreboard from the parent.");
}
static int send_handles_to_child(apr_pool_t *p,
{
"Parent: Unable to duplicate the ready event handle for the child");
return -1;
}
!= APR_SUCCESS) {
"Parent: Unable to send the exit event handle to the child");
return -1;
}
"Parent: Unable to duplicate the exit event handle for the child");
return -1;
}
!= APR_SUCCESS) {
"Parent: Unable to send the exit event handle to the child");
return -1;
}
"Parent: Unable to retrieve the start mutex for the child");
return -1;
}
SYNCHRONIZE, FALSE, 0)) {
"Parent: Unable to duplicate the start mutex to the child");
return -1;
}
!= APR_SUCCESS) {
"Parent: Unable to send the start mutex to the child");
return -1;
}
"Parent: Unable to retrieve the scoreboard handle for the child");
return -1;
}
"Parent: Unable to duplicate the scoreboard handle to the child");
return -1;
}
!= APR_SUCCESS) {
"Parent: Unable to send the scoreboard handle to the child");
return -1;
}
"Parent: Sent the scoreboard to the child");
return 0;
}
/*
* get_listeners_from_parent()
* The listen sockets are opened in the parent. This function, which runs
* exclusively in the child process, receives them from the parent and
* makes them availeble in the child.
*/
static void get_listeners_from_parent(server_rec *s)
{
int lcnt = 0;
/* Set up a default listener if necessary */
if (ap_listeners == NULL) {
ap_listeners = lr;
}
/* Open the pipe to the parent process to receive the inherited socket
* data. The sockets have been set to listening in the parent process.
*
* *** We now do this was back in winnt_rewrite_args
* pipe = GetStdHandle(STD_INPUT_HANDLE);
*/
"Child: Waiting for data for listening socket %pI",
"Child: Unable to read socket data from parent");
}
&WSAProtocolInfo, 0, 0);
if (nsd == INVALID_SOCKET) {
"Child: WSASocket failed to open the inherited socket");
}
"Child: SetHandleInformation failed");
}
}
"Child: retrieved %d listeners from parent", lcnt);
}
{
int lcnt = 0;
/* Run the chain of open sockets. For each socket, duplicate it
* for the target process then send the WSAPROTOCOL_INFO
* (returned by dup socket) to the child.
*/
"Parent: Duplicating socket %d (%pI) and sending it to child process %lu",
lpWSAProtocolInfo) == SOCKET_ERROR) {
"Parent: WSADuplicateSocket failed for socket %d. Check the FAQ.", nsd);
return -1;
}
sizeof(WSAPROTOCOL_INFO), &BytesWritten))
!= APR_SUCCESS) {
"Parent: Unable to write duplicated socket %d to the child.", nsd);
return -1;
}
}
return 0;
}
enum waitlist_e {
waitlist_ready = 0,
waitlist_term = 1
};
{
/* These NEVER change for the lifetime of this parent
*/
static char pidbuf[28];
char *cmd;
char *cwd;
char **env;
int envc;
/* Build the command line. Should look something like this:
* First, get the path to the executable...
*/
"Parent: Failed to get the current path");
}
if (!args) {
/* Build the args array, only once since it won't change
* for the lifetime of this parent process.
*/
!= APR_SUCCESS) {
"Parent: Failed to get full path of %s",
return -1;
}
}
else {
}
/* Create a pipe to send handles to the child */
"Parent: Unable to create child stdin pipe.");
return -1;
}
/* Create the child_ready_event */
if (!waitlist[waitlist_ready]) {
"Parent: Could not create ready event for child process");
return -1;
}
/* Create the child_exit_event */
if (!hExitEvent) {
"Parent: Could not create exit event for child process");
return -1;
}
/* Build the env array */
;
}
if (rv != APR_SUCCESS) {
"Parent: Failed to create the child process.");
return -1;
}
/*
* This error is fatal, mop up the child and move on
* We toggle the child's exit event to cause this child
* to quit even as it is attempting to start.
*/
return -1;
}
/* Important:
* Give the child process a chance to run before dup'ing the sockets.
* We have already set the listening sockets noninheritable, but if
* WSADuplicateSocket runs before the child process initializes
* the listeners will be inherited anyway.
*/
if (rv != WAIT_OBJECT_0) {
/*
* Outch... that isn't a ready signal. It's dead, Jim!
*/
return -1;
}
/*
* This error is fatal, mop up the child and move on
* We toggle the child's exit event to cause this child
* to quit even as it is attempting to start.
*/
return -1;
}
return 0;
}
/***********************************************************************
* master_main()
* master_main() runs in the parent process. It creates the child
* process which handles HTTP requests then waits on one of three
* events:
*
* restart_event
* -------------
* The restart event causes master_main to start a new child process and
* tells the old child process to exit (by setting the child_exit_event).
* The restart event is set as a result of one of the following:
* 1. An apache -k restart command on the command line
* 2. A command received from Windows service manager which gets
* translated into an ap_signal_parent(SIGNAL_PARENT_RESTART)
* call by code in service.c.
* 3. The child process calling ap_signal_parent(SIGNAL_PARENT_RESTART)
* as a result of hitting MaxConnectionsPerChild.
*
* shutdown_event
* --------------
* The shutdown event causes master_main to tell the child process to
* exit and that the server is shutting down. The shutdown event is
* set as a result of one of the following:
* 1. An apache -k shutdown command on the command line
* 2. A command received from Windows service manager which gets
* translated into an ap_signal_parent(SIGNAL_PARENT_SHUTDOWN)
* call by code in service.c.
*
* child process handle
* --------------------
* The child process handle will be signaled if the child process
* exits for any reason. In a normal running server, the signaling
* of this event means that the child process has exited prematurely
* due to a seg fault or other irrecoverable error. For server
* robustness, master_main will restart the child process under this
* condtion.
*
* master_main uses the child_exit_event to signal the child process
* to exit.
**********************************************************************/
#define NUM_WAIT_HANDLES 3
#define CHILD_HANDLE 0
#define SHUTDOWN_HANDLE 1
#define RESTART_HANDLE 2
{
int child_created;
int restart_pending;
int shutdown_pending;
/* Create a single child process */
if (rv < 0)
{
"master_main: create child process failed. Exiting.");
shutdown_pending = 1;
goto die_now;
}
child_created = 1;
}
/* Update the scoreboard. Note that there is only a single active
* child at once.
*/
/* Wait for shutdown or restart events or for child death */
if (rv == WAIT_FAILED) {
/* Something serious is wrong */
"master_main: WaitForMultipleObjects WAIT_FAILED -- doing server shutdown");
shutdown_pending = 1;
}
else if (rv == WAIT_TIMEOUT) {
/* Hey, this cannot happen */
"master_main: WaitForMultipleObjects with INFINITE wait exited with WAIT_TIMEOUT");
shutdown_pending = 1;
}
else if (cld == SHUTDOWN_HANDLE) {
/* shutdown_event signalled */
shutdown_pending = 1;
"Parent: Received shutdown signal -- Shutting down the server.");
if (ResetEvent(shutdown_event) == 0) {
"ResetEvent(shutdown_event)");
}
}
else if (cld == RESTART_HANDLE) {
/* Received a restart event. Prepare the restart_event to be reused
* then signal the child process to exit.
*/
restart_pending = 1;
"Parent: Received restart signal -- Restarting the server.");
if (ResetEvent(restart_event) == 0) {
"Parent: ResetEvent(restart_event) failed.");
}
if (SetEvent(child_exit_event) == 0) {
"Parent: SetEvent for child process %pp failed.",
}
/* Don't wait to verify that the child process really exits,
* just move on with the restart.
*/
}
else {
/* The child process exited prematurely due to a fatal error. */
/* HUH? We did exit, didn't we? */
}
if ( exitcode == APEXIT_CHILDFATAL
|| exitcode == APEXIT_CHILDINIT
|| exitcode == APEXIT_INIT) {
"Parent: child process exited with status %lu -- Aborting.", exitcode);
shutdown_pending = 1;
}
else {
int i;
restart_pending = 1;
"Parent: child process exited with status %lu -- Restarting.", exitcode);
for (i = 0; i < ap_threads_per_child; i++) {
}
}
}
winnt_note_child_killed(/* slot */ 0);
if (restart_pending) {
}
if (shutdown_pending)
{
if (!child_created) {
return 0; /* Tell the caller we do not want to restart */
}
/* This shutdown is only marginally graceful. We will give the
* child a bit of time to exit gracefully. If the time expires,
* the child will be wacked.
*/
}
/* Signal the child processes to exit */
if (SetEvent(child_exit_event) == 0) {
"Parent: SetEvent for child process %pp failed",
}
if (event_handles[CHILD_HANDLE]) {
if (rv == WAIT_OBJECT_0) {
"Parent: Child process exited successfully.");
}
else {
"Parent: Forcing termination of child process %pp",
}
}
return 0; /* Tell the caller we do not want to restart */
}
return 1; /* Tell the caller we want a restart */
}
/* service_nt_main_fn needs to append the StartService() args
* outside of our call stack and thread as the service starts...
*/
/* Remember service_to_start failures to log and fail in pre_config.
* Remember inst_argc and inst_argv for installing or starting the
* service after we preflight the config.
*/
{
*rv = APR_SUCCESS;
switch (query_code) {
case AP_MPMQ_MAX_DAEMON_USED:
break;
case AP_MPMQ_IS_THREADED:
*result = AP_MPMQ_STATIC;
break;
case AP_MPMQ_IS_FORKED:
break;
break;
*result = thread_limit;
break;
case AP_MPMQ_MAX_THREADS:
break;
*result = 0;
break;
*result = 0;
break;
*result = 0;
break;
*result = 0;
break;
break;
case AP_MPMQ_MAX_DAEMONS:
*result = 1;
break;
case AP_MPMQ_MPM_STATE:
break;
case AP_MPMQ_GENERATION:
*result = my_generation;
break;
default:
*rv = APR_ENOTIMPL;
break;
}
return OK;
}
static const char *winnt_get_name(void)
{
return "WinNT";
}
#define SERVICE_UNSET (-1)
static apr_status_t service_to_start_success;
static int inst_argc;
static const char * const *inst_argv;
static const char *service_name = NULL;
{
/* Handle the following SCM aspects in this phase:
*
* -k runservice [transition in service context only]
* -k install
* -k config
* -k uninstall
* -k stop
* -k shutdown (same as -k stop). Maintained for backward compatability.
*
* We can't leave this phase until we know our identity
* and modify the command arguments appropriately.
*
* We do not care if the .conf file exists or is parsable when
* attempting to stop or uninstall a service.
*/
char *def_server_root;
char *binpath;
char optbuf[3];
const char *opt_arg;
int fixed_args;
char *pid;
int running_as_service = 1;
int errout = 0;
/* We wish this was *always* a reservation, but sadly it wasn't so and
* we couldn't break a hard limit prior to NT Kernel 5.1
*/
}
/* AP_PARENT_PID is only valid in the child */
if (pid)
{
/* This is the child */
/* Prevent holding open the (nonexistant) console */
ap_real_exit_code = 0;
/* The parent gave us stdin, we need to remember this
* handle, and no longer inherit it at our children
* (we can't slurp it up now, we just aren't ready yet).
* The original handle is closed below, at apr_file_dup2()
*/
}
/* The parent gave us stdout of the NUL device,
* and expects us to suck up stdin of all of our
* shared handles and data from the parent.
* Don't infect child processes with our stdin
* handle, use another handle to NUL!
*/
{
}
/* This child needs the existing stderr opened for logging,
* already
*/
/* The parent is responsible for providing the
* COMPLETE ARGUMENTS REQUIRED to the child.
*
* No further argument parsing is needed, but
* for good measure we will provide a simple
* signal string for later testing.
*/
signal_arg = "runchild";
return;
}
/* This is the parent, we have a long way to go :-) */
/* This behavior is voided by setting real_exit_code to 0 */
/* Rewrite process->argv[];
*
* strip out -k signal into signal_arg
* strip out -n servicename and set the names
* add default -d serverroot from the path of this executable
*
* The end result will look like:
*
* The invocation command (%0)
* The -d serverroot default from the running executable
* The requested service's (-n) registry ConfigArgs
* The WinNT SCM's StartService() args
*/
!= APR_SUCCESS) {
}
/* WARNING: There is an implict assumption here that the
* executable resides in ServerRoot or ServerRoot\bin
*/
if (def_server_root > binpath) {
}
/* Use process->pool so that the rewritten argv
* lasts for the lifetime of the server process,
* because pconf will be destroyed after the
* initial pre-flight of the config parser.
*/
sizeof(const char *));
optbuf[0] = '-';
switch (optbuf[1]) {
/* Shortcuts; include the -w option to hold the window open on error.
* This must not be toggled once we reset ap_real_exit_code to 0!
*/
case 'w':
if (ap_real_exit_code)
ap_real_exit_code = 2;
break;
case 'n':
opt_arg);
break;
case 'k':
break;
case 'E':
errout = 1;
/* Fall through so the Apache main() handles the 'E' arg */
default:
*(const char **)apr_array_push(mpm_new_argv) =
if (opt_arg) {
}
break;
}
}
/* back up to capture the bad argument */
}
*(const char **)apr_array_push(mpm_new_argv) =
}
/* Track the number of args actually entered by the user */
/* Provide a default 'run' -k arg to simplify signal_arg tests */
if (!signal_arg)
{
signal_arg = "run";
running_as_service = 0;
}
{
/* Start the NT Service _NOW_ because the WinNT SCM is
* expecting us to rapidly assume control of our own
* process, the SCM will tell us our service name, and
* may have extra StartService() command arguments to
* add for us.
*
* The SCM will generally invoke the executable with
* the c:\win\system32 default directory. This is very
* lethal if folks use ServerRoot /foopath on windows
* without a drive letter. Change to the default root
* (path to apache root, above /bin) for safety.
*/
/* Any other process has a console, so we don't to begin
* a Win9x service until the configuration is parsed and
* any command line errors are reported.
*
* We hold the return value so that we can die in pre_config
* after logging begins, and the failure can land in the log.
*/
if (!errout) {
}
if (service_to_start_success == APR_SUCCESS) {
}
/* Open a null handle to soak stdout in this process.
* Windows service processes are missing any file handle
* trouble with invocations of apr_file_open_stdout()
*/
== APR_SUCCESS)
}
}
/* Get the default for any -k option, except run */
}
{
if (service_set == APR_SUCCESS)
{
"%s: Service is already installed.", service_name);
}
}
else if (running_as_service)
{
if (service_set == APR_SUCCESS)
{
/* Attempt to Uninstall, or stop, before
* we can read the arguments or .conf files
*/
rv = mpm_service_uninstall();
}
exit(0);
}
if (rv == APR_SUCCESS) {
"Using ConfigArgs of the installed service "
"\"%s\".", service_name);
}
else {
"No installed ConfigArgs for the service "
"\"%s\", using Apache defaults.", service_name);
}
}
else
{
"No installed service named \"%s\".", service_name);
}
}
{
"No installed service named \"%s\".", service_name);
}
/* Track the args actually entered by the user.
* These will be used for the -k install parameters, as well as
* for the -k start service override arguments.
*/
/* Now, do service install or reconfigure then proceed to
* post_config to test the installed configuration.
*/
/* Reconfigure the service */
if (rv != APR_SUCCESS) {
}
"service can be started.\n");
}
/* Install the service */
if (rv != APR_SUCCESS) {
}
"service can be started.\n");
}
}
{
/* Handle the following SCM aspects in this phase:
*
* -k runservice [WinNT errors logged from rewrite_args]
*/
/* Initialize shared static objects.
* TODO: Put config related statics into an sconf structure.
*/
if (ap_exists_config_define("ONE_PROCESS") ||
ap_exists_config_define("DEBUG"))
one_process = -1;
/* XXX: presume proper privilages; one nice thing would be
* a loud emit if running as "LocalSystem"/"SYSTEM" to indicate
* they should change to a user with write access to logs/ alone.
*/
&& (service_to_start_success != APR_SUCCESS)) {
"%s: Unable to start the service manager.",
}
else if (!one_process && !my_generation) {
/* Open a null handle to soak stdout in this process.
* We need to emulate apr_proc_detach, unix performs this
* same check in the pre_config hook (although it is
* arguably premature). Services already fixed this.
*/
pproc)) == APR_SUCCESS) {
== APR_SUCCESS)
}
}
return OK;
}
{
int is_parent;
static int restart_num = 0;
int startup = 0;
/* We want this only in the parent and only the first time around */
if (is_parent && restart_num++ == 0) {
startup = 1;
}
if (thread_limit > MAX_THREAD_LIMIT) {
if (startup) {
"WARNING: ThreadLimit of %d exceeds compile-time "
"limit of", thread_limit);
" %d threads, decreasing to %d.",
} else if (is_parent) {
"ThreadLimit of %d exceeds compile-time limit "
"of %d, decreasing to match",
}
}
else if (thread_limit < 1) {
if (startup) {
"WARNING: ThreadLimit of %d not allowed, "
"increasing to 1.", thread_limit);
} else if (is_parent) {
"ThreadLimit of %d not allowed, increasing to 1",
}
thread_limit = 1;
}
/* You cannot change ThreadLimit across a restart; ignore
* any such attempts.
*/
if (!first_thread_limit) {
}
else if (thread_limit != first_thread_limit) {
/* Don't need a startup console version here */
if (is_parent) {
"changing ThreadLimit to %d from original value "
"of %d not allowed during restart",
}
}
if (ap_threads_per_child > thread_limit) {
if (startup) {
"WARNING: ThreadsPerChild of %d exceeds ThreadLimit "
"of", ap_threads_per_child);
" %d threads, decreasing to %d.",
" To increase, please see the ThreadLimit "
"directive.");
} else if (is_parent) {
"ThreadsPerChild of %d exceeds ThreadLimit "
"of %d, decreasing to match",
}
}
else if (ap_threads_per_child < 1) {
if (startup) {
"WARNING: ThreadsPerChild of %d not allowed, "
"increasing to 1.", ap_threads_per_child);
} else if (is_parent) {
"ThreadsPerChild of %d not allowed, increasing to 1",
}
ap_threads_per_child = 1;
}
return OK;
}
{
static int restart_num = 0;
apr_status_t rv = 0;
/* Handle the following SCM aspects in this phase:
*
* -k install (catch and exit as install was handled in rewrite_args)
* -k config (catch and exit as config was handled in rewrite_args)
* -k start
* -k restart
* -k runservice [Win95, only once - after we parsed the config]
*
* because all of these signals are useful _only_ if there
* is a valid conf\httpd.conf environment to start.
*
* We reached this phase by avoiding errors that would cause
* these options to fail unexpectedly in another process.
*/
/* Service install happens in the rewrite_args hooks. If we
* made it this far, the server configuration is clean and the
* service will successfully start.
*/
exit(0);
}
/* Service reconfiguration happens in the rewrite_args hooks. If we
* made it this far, the server configuration is clean and the
* service will successfully start.
*/
exit(0);
}
/* Close the listening sockets. */
}
}
}
if (parent_pid == my_pid)
{
if (restart_num++ == 1)
{
/* This code should be run once in the parent and not run
* across a restart
*/
/* Create shutdown event, apPID_shutdown, where PID is the parent
* Apache process ID. Shutdown is signaled by 'apache -k shutdown'.
*/
if (!shutdown_event) {
"Parent: Cannot create shutdown event %s", signal_shutdown_name);
CleanNullACL((void *)sa);
return HTTP_INTERNAL_SERVER_ERROR;
}
/* Create restart event, apPID_restart, where PID is the parent
* Apache process ID. Restart is signaled by 'apache -k restart'.
*/
if (!restart_event) {
"Parent: Cannot create restart event %s", signal_restart_name);
CleanNullACL((void *)sa);
return HTTP_INTERNAL_SERVER_ERROR;
}
CleanNullACL((void *)sa);
/* Create the start mutex, as an unnamed object for security.
* Ths start mutex is used during a restart to prevent more than
* one child process from entering the accept loop at once.
*/
if (rv != APR_SUCCESS) {
"%s: Unable to create the start_mutex.",
return HTTP_INTERNAL_SERVER_ERROR;
}
}
/* Always reset our console handler to be the first, even on a restart
* because some modules (e.g. mod_perl) might have set a console
* handler to terminate the process.
*/
}
else /* parent_pid != my_pid */
{
}
return OK;
}
/* This really should be a post_config hook, but the error log is already
* redirected by that point, so we need to do this in the open_logs phase.
*/
{
/* Initialize shared static objects.
*/
if (parent_pid != my_pid) {
return OK;
}
/* We cannot initialize our listeners if we are restarting
* (the parent process already has glomed on to them)
* nor should we do so for service reconfiguration
* (since the service may already be running.)
*/
return OK;
}
if (ap_setup_listeners(s) < 1) {
NULL, "no listening sockets available, shutting down");
return DONE;
}
return OK;
}
{
/* This is a child process, not in single process mode */
if (!one_process) {
/* Set up events and the scoreboard */
/* Set up the listeners */
/* Done reading from the parent, close that channel */
}
else {
/* Single process mode - this lock doesn't even need to exist */
if (rv != APR_SUCCESS) {
"%s child: Unable to init the start_mutex.",
}
/* Borrow the shutdown_even as our _child_ loop exit event */
}
}
{
static int restart = 0; /* Default is "not a restart" */
/* ### If non-graceful restarts are ever introduced - we need to rerun
* the pre_mpm hook on subsequent non-graceful restarts. But Win32
* has only graceful style restarts - and we need this hook to act
* the same on Win32 as on Unix.
*/
/* Set up the scoreboard. */
return DONE;
}
}
{
/* The child process or in one_process (debug) mode
*/
"Child process is running");
"Child process is exiting");
return DONE;
}
else
{
/* A real-honest to goodness parent */
"%s configured -- resuming normal operations",
"Server built: %s", ap_get_server_built());
ap_log_command_line(plog, s);
if (!restart)
{
/* Shutting down. Clean up... */
return DONE;
}
}
return OK; /* Restart */
}
static void winnt_hooks(apr_pool_t *p)
{
/* Our open_logs hook function must run before the core's, or stderr
* will be redirected to a file, and the messages won't print to the
* console.
*/
}
winnt_rewrite_args, /* hook to run before apache parses args */
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
winnt_cmds, /* command apr_table_t */
winnt_hooks /* register_hooks */
};
#endif /* def WIN32 */