From 7a3cfbfcb650edb2400cfef86cb68b982887797e Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Tue, 12 Feb 2002 00:14:47 +0000 Subject: [PATCH] Perform a serious scrubbing of the child process, before we report that we failed to create the child. Cleans up CloseHandle() destruction to match all created handles - and postpone populating the *child_exit_event until we succeed. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93369 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/winnt/mpm_winnt.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index ad10ec4b76..a6d12105af 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -1434,6 +1434,7 @@ static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_ HANDLE hPipeWrite; HANDLE hNullOutput; HANDLE hShareError; + HANDLE hExitEvent; HANDLE hCurrentProcess = GetCurrentProcess(); SECURITY_ATTRIBUTES sa; @@ -1530,8 +1531,8 @@ static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_ } /* Create the child_exit_event */ - *child_exit_event = CreateEvent(NULL, TRUE, FALSE, NULL); - if (!(*child_exit_event)) { + hExitEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!hExitEvent) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Could not create exit event for child process"); CloseHandle(hPipeWrite); @@ -1587,7 +1588,7 @@ static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_ NULL, &si, &pi); - /* Undo everything we created for the child only + /* Undo everything created for the child alone */ CloseHandle(pi.hThread); CloseHandle(hPipeRead); @@ -1604,17 +1605,25 @@ static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_ if (!rv) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Failed to create the child process."); + CloseHandle(hExitEvent); CloseHandle(hPipeWrite); CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); return -1; } ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf, "Parent: Created child process %d", pi.dwProcessId); - if (send_handles_to_child(p, *child_exit_event, pi.hProcess, hPipeWrite)) { + if (send_handles_to_child(p, hExitEvent, pi.hProcess, hPipeWrite)) { + /* + * 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. + */ + SetEvent(hExitEvent); + CloseHandle(hExitEvent); CloseHandle(hPipeWrite); + CloseHandle(pi.hProcess); return -1; } @@ -1629,13 +1638,22 @@ static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_ Sleep(1000); if (send_listeners_to_child(p, pi.dwProcessId, hPipeWrite)) { + /* + * 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. + */ + SetEvent(hExitEvent); + CloseHandle(hExitEvent); CloseHandle(hPipeWrite); + CloseHandle(pi.hProcess); return -1; } CloseHandle(hPipeWrite); *child_proc = pi.hProcess; + *child_exit_event = hExitEvent; return 0; } -- 2.40.0