mpm_winnt.c revision 26d590c0e5338f66ca1aad6f925374843fac5121
7cb128dc4cae2a03a742f63ba7afee23c78e3af0Phil Carmody/* ====================================================================
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * The Apache Software License, Version 1.1
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * Redistribution and use in source and binary forms, with or without
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * modification, are permitted provided that the following conditions
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * 1. Redistributions of source code must retain the above copyright
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * notice, this list of conditions and the following disclaimer.
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * 2. Redistributions in binary form must reproduce the above copyright
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * notice, this list of conditions and the following disclaimer in
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * the documentation and/or other materials provided with the
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * distribution.
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * 3. The end-user documentation included with the redistribution,
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * if any, must include the following acknowledgment:
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * "This product includes software developed by the
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * Apache Software Foundation (http://www.apache.org/)."
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * Alternately, this acknowledgment may appear in the software itself,
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * if and wherever such third-party acknowledgments normally appear.
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * 4. The names "Apache" and "Apache Software Foundation" must
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * not be used to endorse or promote products derived from this
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * software without prior written permission. For written
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * permission, please contact apache@apache.org.
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * 5. Products derived from this software may not be called "Apache",
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * nor may "Apache" appear in their name, without prior written
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * permission of the Apache Software Foundation.
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * SUCH DAMAGE.
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * ====================================================================
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * This software consists of voluntary contributions made by many
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * individuals on behalf of the Apache Software Foundation. For more
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * information on the Apache Software Foundation, please see
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * Portions of this software are based upon public domain software
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * originally written at the National Center for Supercomputing Applications,
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen * University of Illinois, Urbana-Champaign.
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen#include "http_core.h" /* for get_remote_host */
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen/* Definitions of WINNT MPM specific config globals */
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainenstatic unsigned int g_blocked_threads = 0;
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainenstatic HANDLE shutdown_event; /* used to signal the parent to shutdown */
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainenstatic HANDLE restart_event; /* used to signal the parent to restart */
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainenstatic HANDLE exit_event; /* used by parent to signal the child to exit */
static int one_process = 0;
int ap_threads_per_child = 0;
static int num_completion_contexts = 0;
if (pCompContext) {
if (qtail)
if (qhead) {
if (!qhead)
if (!pCompContext) {
static int reported = 0;
if (!reported) {
return NULL;
return NULL;
return pCompContext;
if (pCompContext)
return APR_SUCCESS;
return NULL;
if (ordinal)
return NULL;
apr_set_os_error(0);
|| apr_get_os_error()) {
return NULL;
|| apr_get_os_error()) {
return NULL;
return sa;
if( sa ) {
if (!bFirst)
return dwRet;
static int volatile is_graceful = 0;
return is_graceful;
HANDLE e;
char *signal_name;
if (one_process) {
switch(type) {
case SIGNAL_PARENT_SHUTDOWN:
case SIGNAL_PARENT_RESTART:
if (SetEvent(e) == 0) {
CloseHandle(e);
CloseHandle(e);
return (lr);
return NULL;
int num_listeners = 0;
if (!lr)
&WSAProtocolInfo, 0, 0);
return num_listeners;
typedef struct joblist_s {
int sock;
} joblist;
typedef struct globals_s {
int jobcount;
} globals;
static int remove_job(void)
int sock;
return (sock);
int csd;
int count_select_errors = 0;
int rc;
int clen;
while (!shutdown_in_progress) {
if (csd < 0) {
int len;
if (!context) {
return NULL;
return NULL;
return context;
int lasterror;
while (!shutdown_in_progress) {
if (!pCompContext) {
goto again;
if (shutdown_in_progress)
goto again;
goto again;
sizeof(nlsd))) {
if (!shutdown_in_progress) {
int rc;
if (workers_may_exit) {
return NULL;
if (!rc) {
switch (CompKey) {
case IOCP_CONNECTION_ACCEPTED:
case IOCP_SHUTDOWN:
return NULL;
return NULL;
return pCompContext;
static int requests_this_child = 0;
conn_rec *c;
if (!context) {
if (ap_max_requests_per_child) {
if (!disconnected) {
(*thread_cnt)--;
static void child_main()
char* exit_event_name;
int tid;
int rv;
int cld;
if (one_process) {
exit(0);
NULL,
for (i = 0; i < nthreads; i++) {
(void *) i, 0, &tid);
(void *) i, 0, &tid);
else if (cld == 0) {
for (i = 0; i < nthreads; i++) {
while (g_blocked_threads > 0) {
for (i=g_blocked_threads; i > 0; i--) {
while (qhead) {
while (nthreads) {
for (i = 0; i < nthreads; i++) {
int rv;
char *pCommand;
char *pEnvVar;
char *pEnvBlock;
int iEnvBlockLen;
* C:/apache/bin/apache.exe -f ap_server_confname
} else if (rv == 0) {
while (_environ[i]) {
while (_environ[i]) {
NULL,
if (!(*child_exit_event)) {
int nsd;
* call by code in service.c.
* call by code in service.c.
#define CHILD_HANDLE 0
int restart_pending = 0;
int shutdown_pending = 0;
if (rv < 0)
goto die_now;
if (shutdown_pending)
switch(query_code){
case AP_MPMQ_MAX_DAEMON_USED:
return APR_SUCCESS;
case AP_MPMQ_IS_THREADED:
return APR_SUCCESS;
case AP_MPMQ_IS_FORKED:
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
case AP_MPMQ_MAX_THREADS:
return APR_SUCCESS;
*result = 0;
return APR_SUCCESS;
*result = 0;
return APR_SUCCESS;
*result = 0;
return APR_SUCCESS;
*result = 0;
return APR_SUCCESS;
return APR_SUCCESS;
case AP_MPMQ_MAX_DAEMONS:
*result = 0;
return APR_SUCCESS;
return APR_ENOTIMPL;
static int inst_argc;
static const char * const *inst_argv;
char *def_server_root;
const char *optarg;
int fixed_args;
char *pid;
if (pid)
optarg);
if (optarg) {
if (!signal_arg)
running_as_service = 0;
else if (running_as_service)
* in these cases we -don't- care if httpd.conf has config errors!
exit(0);
static int winnt_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec* server)
static int restart_num = 0;
* is a valid conf\httpd.conf environment to start.
if (!shutdown_event) {
return HTTP_INTERNAL_SERVER_ERROR;
if (!restart_event) {
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
ap_server_conf = s;
if (one_process) {
child_main();
if (!restart) {
return err;
return NULL;
const char *value)
return NULL;
{ NULL }