#include "mpm_winnt.h"
#include "mpm_common.h"
+typedef HANDLE thread;
+
/*
* Definitions of WINNT MPM specific config globals
*/
int ap_max_requests_per_child=0;
int ap_daemons_to_start=0;
-static event *exit_event;
-HANDLE maintenance_event;
+static HANDLE exit_event;
+static HANDLE maintenance_event;
apr_lock_t *start_mutex;
DWORD my_pid;
DWORD parent_pid;
* or thrown out entirely...
*/
-typedef void semaphore;
-typedef void event;
-
-static semaphore *
-create_semaphore(int initial)
+static HANDLE create_semaphore(int initial)
{
return(CreateSemaphore(NULL, initial, 1000000, NULL));
}
-static void acquire_semaphore(semaphore *semaphore_id)
+static void acquire_semaphore(HANDLE semaphore_id)
{
int rv;
return;
}
-static int release_semaphore(semaphore *semaphore_id)
+static int release_semaphore(HANDLE semaphore_id)
{
return(ReleaseSemaphore(semaphore_id, 1, NULL));
}
-static void destroy_semaphore(semaphore *semaphore_id)
+static void destroy_semaphore(HANDLE semaphore_id)
{
CloseHandle(semaphore_id);
}
*/
typedef struct globals_s {
- semaphore *jobsemaphore;
+ HANDLE jobsemaphore;
joblist *jobhead;
joblist *jobtail;
apr_lock_t *jobmutex;
} while (csd < 0 && APR_STATUS_IS_EINTR(apr_get_netos_error()));
if (csd < 0) {
- if (apr_get_netos_error() == APR_FROM_OS_ERROR(WSAECONNABORTED)) {
+ if (APR_STATUS_IS_ECONNABORTED(apr_get_netos_error())) {
ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_netos_error(), server_conf,
"accept: (client socket)");
}
memset(&context->sa_client, '\0', sizeof(context->sa_client));
}
- context->conn_io = ap_bcreate(context->ptrans, B_RDWR);
-
/* do we NEED_DUPPED_CSD ?? */
return context;
if (!rc) {
rc = apr_get_os_error();
if (rc == APR_FROM_OS_ERROR(ERROR_OPERATION_ABORTED)) {
- ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, server_conf,
- "Child %d: - Draining an ABORTED packet off "
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, server_conf,
+ "Child %d: Draining an ABORTED packet off "
"the AcceptEx completion port.", my_pid);
continue;
}
break;
}
ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, server_conf,
- "Child %d: - Draining and discarding an active connection "
+ "Child %d: Draining and discarding an active connection "
"off the AcceptEx completion port.", my_pid);
context = (PCOMP_CONTEXT) pol;
if (context && bCleanUp) {
}
apr_create_pool(&context->ptrans, _pconf);
- context->conn_io = ap_bcreate(context->ptrans, B_RDWR);
- context->recv_buf = context->conn_io->inbase;
- context->recv_buf_size = context->conn_io->bufsiz - 2*PADDED_ADDR_SIZE;
+ /* recv_buf must be large enough to hold the remote and local
+ * addresses. Note that recv_buf_size is the amount of recv_buf
+ * available for AcceptEx to receive bytes into. Since we
+ * don't want AcceptEx to do a recv, set the size to 0.
+ */
+ context->recv_buf = apr_pcalloc(_pconf, 2*PADDED_ADDR_SIZE);
+ context->recv_buf_size = 0;
/* AcceptEx on the completion context. The completion context will be signaled
* when a connection is accepted. */
if (!AcceptEx(nsd, context->accept_socket,
context->recv_buf,
- 0, //context->recv_buf_size,
+ context->recv_buf_size,
PADDED_ADDR_SIZE, PADDED_ADDR_SIZE,
&BytesRead,
(LPOVERLAPPED) context)) {
/* reset the buffer pools */
apr_clear_pool(context->ptrans);
context->sock = NULL;
- context->conn_io = ap_bcreate(context->ptrans, B_RDWR);
- context->recv_buf = context->conn_io->inbase;
- context->recv_buf_size = context->conn_io->bufsiz - 2*PADDED_ADDR_SIZE;
/* recreate and initialize the accept socket if it is not being reused */
apr_get_os_sock(&nsd, context->lr->sd);
}
}
- if (!AcceptEx(nsd, context->accept_socket, context->recv_buf, 0,
- PADDED_ADDR_SIZE, PADDED_ADDR_SIZE, &BytesRead,
+ if (!AcceptEx(nsd, context->accept_socket,
+ context->recv_buf,
+ context->recv_buf_size,
+ PADDED_ADDR_SIZE,
+ PADDED_ADDR_SIZE,
+ &BytesRead,
(LPOVERLAPPED) context)) {
+
rc = apr_get_netos_error();
if (rc != APR_FROM_OS_ERROR(ERROR_IO_PENDING)) {
- ap_log_error(APLOG_MARK, APLOG_INFO, rc, server_conf,
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, rc, server_conf,
"reset_acceptex_context: AcceptEx failed for "
- "listening socket: %d and accept socket: %d",
+ "listening socket: %d and accept socket: %d. Getting a new accept socket.",
nsd, context->accept_socket);
closesocket(context->accept_socket);
context->accept_socket = INVALID_SOCKET;
* we see this now and not during AcceptEx(). Reset the
* AcceptEx context and continue...
*/
- ap_log_error(APLOG_MARK,APLOG_INFO, rc, server_conf,
+ ap_log_error(APLOG_MARK,APLOG_DEBUG, rc, server_conf,
"Child %d: - GetQueuedCompletionStatus() failed",
my_pid);
/* Reset the completion context */
/* Sometimes we catch ERROR_OPERATION_ABORTED completion packets
* from the old child process (during a restart). Ignore them.
*/
- ap_log_error(APLOG_MARK,APLOG_INFO, rc, server_conf,
+ ap_log_error(APLOG_MARK,APLOG_DEBUG, rc, server_conf,
"Child %d: - Draining ERROR_OPERATION_ABORTED packet off "
"the completion port.", my_pid);
}
}
/* Received a connection */
- context->conn_io->incnt = BytesRead;
GetAcceptExSockaddrs(context->recv_buf,
- 0, //context->recv_buf_size,
+ context->recv_buf_size,
PADDED_ADDR_SIZE,
PADDED_ADDR_SIZE,
&context->sa_server,
static void worker_main(int child_num)
{
PCOMP_CONTEXT context = NULL;
+ apr_os_sock_info_t sockinfo;
while (1) {
conn_rec *c;
if (!context)
break;
sock_disable_nagle(context->accept_socket);
- apr_put_os_sock(&context->sock, &context->accept_socket, context->ptrans);
+
+ sockinfo.os_sock = &context->accept_socket;
+ sockinfo.local = context->sa_server;
+ sockinfo.remote = context->sa_client;
+ sockinfo.family = APR_INET;
+ sockinfo.type = SOCK_STREAM;
+ apr_make_os_sock(&context->sock, &sockinfo, context->ptrans);
c = ap_new_connection(context->ptrans, server_conf, context->sock,
- (struct sockaddr_in *) context->sa_client,
- (struct sockaddr_in *) context->sa_server,
child_num);
ap_process_connection(c);
}
}
- ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, server_conf,
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, server_conf,
"Child %d: Thread exiting.", my_pid);
#if 0
/* TODO: Add code to clean-up completion contexts here */
}
-static void cleanup_thread(thread **handles, int *thread_cnt, int thread_to_clean)
+static void cleanup_thread(thread *handles, int *thread_cnt, int thread_to_clean)
{
int i;
char* exit_event_name;
int nthreads = ap_threads_per_child;
int tid;
- thread **child_handles;
+ thread *child_handles;
int rv;
time_t end_time;
int i;
/* Create the worker thread pool */
ap_log_error(APLOG_MARK,APLOG_INFO, APR_SUCCESS, server_conf,
"Child %d: Starting %d worker threads.", my_pid, nthreads);
- child_handles = (thread *) alloca(nthreads * sizeof(int));
+ child_handles = (thread) alloca(nthreads * sizeof(int));
for (i = 0; i < nthreads; i++) {
- child_handles[i] = (thread *) _beginthreadex(NULL, 0, (LPTHREAD_START_ROUTINE) worker_main,
- NULL, 0, &tid);
+ child_handles[i] = (thread) _beginthreadex(NULL, 0, (LPTHREAD_START_ROUTINE) worker_main,
+ NULL, 0, &tid);
}
/* Begin accepting connections */
"Parent: Unable to write duplicated socket %d to the child.", lr->sd );
return -1;
}
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, APR_SUCCESS, server_conf,
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, APR_SUCCESS, server_conf,
"Parent: BytesWritten = %d WSAProtocolInfo = %x20", BytesWritten, *lpWSAProtocolInfo);
}
if (osver.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
shutdown_pending = 1;
printf("shutdown event signaled\n");
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, APR_SUCCESS, s,
- "master_main: Shutdown event signaled -- doing server shutdown.");
+ "Parent: SHUTDOWN EVENT SIGNALED -- Shutting down the server.");
if (ResetEvent(shutdown_event) == 0) {
ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s,
"ResetEvent(shutdown_event)");
int children_to_kill = current_live_processes;
restart_pending = 1;
ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, s,
- "master_main: Restart event signaled. Doing a graceful restart.");
+ "Parent: RESTART EVENT SIGNALED -- Restarting the server.");
if (ResetEvent(restart_event) == 0) {
ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s,
"master_main: ResetEvent(restart_event) failed.");
*/
restart_pending = 1;
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, APR_SUCCESS, server_conf,
- "master_main: Child process failed. Restarting the child process.");
+ "Parent: CHILD PROCESS FAILED -- Restarting the child process.");
ap_assert(cld < current_live_processes);
cleanup_process(process_handles, process_kill_events, cld, ¤t_live_processes);
/* APD2("main_process: child in slot %d died", rv); */
}
for (i = 0; i < current_live_processes; i++) {
ap_log_error(APLOG_MARK,APLOG_ERR|APLOG_NOERRNO, APR_SUCCESS, server_conf,
- "forcing termination of child #%d (handle %d)", i, process_handles[i]);
+ "Parent: Forcing termination of child #%d (handle %d)", i, process_handles[i]);
TerminateProcess((HANDLE) process_handles[i], 1);
}
return 0; /* Tell the caller we do not want to restart */
}
-#define SERVICE_UNNAMED -1
+#define SERVICE_UNNAMED (-1)
/* service_nt_main_fn needs to append the StartService() args
* outside of our call stack and thread as the service starts...
static apr_status_t service_to_start_success;
static int inst_argc;
-static char **inst_argv;
+static const char * const *inst_argv;
void winnt_rewrite_args(process_rec *process)
{
char fnbuf[MAX_PATH];
char optbuf[3];
const char *optarg;
- const char **new_arg;
int fixed_args;
char *pid;
apr_getopt_t *opt;
if (pid)
{
/* This is the child */
- parent_pid = (DWORD) atol(pid);
my_pid = GetCurrentProcessId();
+ parent_pid = (DWORD) atol(pid);
/* The parent is responsible for providing the
* COMPLETE ARGUMENTS REQUIRED to the child.
* The requested service's (-n) registry ConfigArgs
* The WinNT SCM's StartService() args
*/
-
if (!GetModuleFileName(NULL, fnbuf, sizeof(fnbuf))) {
- /* WARNING: There is an implict assumption here that the
- * executable resides in the ServerRoot!
- */
rv = apr_get_os_error();
ap_log_error(APLOG_MARK,APLOG_ERR, rv, NULL,
- "Failed to get the running module's file name");
+ "Failed to get the path of Apache.exe");
exit(1);
}
+ /* WARNING: There is an implict assumption here that the
+ * executable resides in ServerRoot or ServerRoot\bin
+ */
def_server_root = (char *) apr_filename_of_pathname(fnbuf);
if (def_server_root > fnbuf) {
*(def_server_root - 1) = '\0';
- def_server_root = ap_os_canonical_filename(process->pool, fnbuf);
+ def_server_root = (char *) apr_filename_of_pathname(fnbuf);
+ if (!strcasecmp(def_server_root, "bin"))
+ *(def_server_root - 1) = '\0';
}
+ def_server_root = ap_os_canonical_filename(process->pool, fnbuf);
/* 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.
*/
-
- mpm_new_argv = apr_make_array(process->pool, process->argc + 2, sizeof(char *));
- new_arg = (char**) apr_push_array(mpm_new_argv);
- *new_arg = (char *) process->argv[0];
-
- new_arg = (char**) apr_push_array(mpm_new_argv);
- *new_arg = "-d";
- new_arg = (char**) apr_push_array(mpm_new_argv);
- *new_arg = def_server_root;
+ mpm_new_argv = apr_make_array(process->pool, process->argc + 2,
+ sizeof(const char *));
+ *(const char **)apr_push_array(mpm_new_argv) = process->argv[0];
+ *(const char **)apr_push_array(mpm_new_argv) = "-d";
+ *(const char **)apr_push_array(mpm_new_argv) = def_server_root;
fixed_args = mpm_new_argv->nelts;
- optbuf[0] = '-'; optbuf[2] = '\0';
+ optbuf[0] = '-';
+ optbuf[2] = '\0';
apr_initopt(&opt, process->pool, process->argc, (char**) process->argv);
while (apr_getopt(opt, "n:k:iu" AP_SERVER_BASEARGS,
optbuf + 1, &optarg) == APR_SUCCESS) {
signal_arg = "uninstall";
break;
default:
- new_arg = (char**) apr_push_array(mpm_new_argv);
- *new_arg = apr_pstrdup(process->pool, optbuf);
+ *(const char **)apr_push_array(mpm_new_argv) =
+ apr_pstrdup(process->pool, optbuf);
+
if (optarg) {
- new_arg = (char**) apr_push_array(mpm_new_argv);
- *new_arg = optarg;
+ *(const char **)apr_push_array(mpm_new_argv) = optarg;
}
break;
}
"Using ConfigArgs of the installed service "
"\"%s\".", display_name);
}
- else {
+ else {
ap_log_error(APLOG_MARK,APLOG_INFO, rv, NULL,
"No installed ConfigArgs for the service "
"\"%s\", using Apache defaults.", display_name);
- }
+ }
}
else
{
* These will be used for the -k install parameters, as well as
* for the -k start service override arguments.
*/
- inst_argv = (char**) mpm_new_argv->elts + mpm_new_argv->nelts - inst_argc;
+ inst_argv = (const char * const *)mpm_new_argv->elts
+ + mpm_new_argv->nelts - inst_argc;
process->argc = mpm_new_argv->nelts;
- process->argv = (char**) mpm_new_argv->elts;
+ process->argv = (const char * const *) mpm_new_argv->elts;
}
*/
apr_status_t rv;
- if (getenv("ONE_PROCESS"))
+ if (ap_exists_config_define("ONE_PROCESS"))
one_process = -1;
if (ap_exists_config_define("ONE_PROCESS"))
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
winnt_cmds, /* command apr_table_t */
- NULL, /* handlers */
winnt_hooks /* register_hooks */
};