From: Jeff Trawick Date: Thu, 26 Sep 2013 20:08:33 +0000 (+0000) Subject: WinNT MPM: Exit the child if the parent process crashes or is terminated. X-Git-Tag: 2.5.0-alpha~5005 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90289779b6f98f6f8b443e2caa312d55c6021a13;p=apache WinNT MPM: Exit the child if the parent process crashes or is terminated. Submitted by: Oracle, via trawick The original modification was made some years ago for Oracle HTTP Server by an Oracle employee. trawick made additional changes for style and for trunk/2.4.x changes. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1526666 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 11a9d26ff2..88c80a88c0 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) WinNT MPM: Exit the child if the parent process crashes or is terminated. + [Oracle Corporation] + *) ldap: Support ldaps when using the Microsoft LDAP SDK. PR 54626. [Jean-Frederic Clere] diff --git a/docs/log-message-tags/next-number b/docs/log-message-tags/next-number index 1232cc3bd2..166c7ce5e9 100644 --- a/docs/log-message-tags/next-number +++ b/docs/log-message-tags/next-number @@ -1 +1 @@ -2538 +2539 diff --git a/server/mpm/winnt/child.c b/server/mpm/winnt/child.c index cb37fc9f3a..49b5c2be66 100644 --- a/server/mpm/winnt/child.c +++ b/server/mpm/winnt/child.c @@ -951,12 +951,12 @@ static void create_listener_thread(void) } -void child_main(apr_pool_t *pconf) +void child_main(apr_pool_t *pconf, DWORD parent_pid) { apr_status_t status; apr_hash_t *ht; ap_listen_rec *lr; - HANDLE child_events[2]; + HANDLE child_events[3]; HANDLE *child_handles; int listener_started = 0; int threads_created = 0; @@ -966,6 +966,7 @@ void child_main(apr_pool_t *pconf) DWORD tid; int rv; int i; + int num_events; apr_pool_create(&pchild, pconf); apr_pool_tag(pchild, "pchild"); @@ -983,6 +984,15 @@ void child_main(apr_pool_t *pconf) child_events[0] = exit_event; child_events[1] = max_requests_per_child_event; + if (parent_pid != my_pid) { + child_events[2] = OpenProcess(PROCESS_ALL_ACCESS, FALSE, parent_pid); + num_events = 3; + } + else { + /* presumably -DONE_PROCESS */ + num_events = 2; + } + /* * Wait until we have permission to start accepting connections. * start_mutex is used to ensure that only one child ever @@ -1112,10 +1122,10 @@ void child_main(apr_pool_t *pconf) */ while (1) { #if !APR_HAS_OTHER_CHILD - rv = WaitForMultipleObjects(2, (HANDLE *)child_events, FALSE, INFINITE); + rv = WaitForMultipleObjects(num_events, (HANDLE *)child_events, FALSE, INFINITE); cld = rv - WAIT_OBJECT_0; #else - rv = WaitForMultipleObjects(2, (HANDLE *)child_events, FALSE, 1000); + rv = WaitForMultipleObjects(num_events, (HANDLE *)child_events, FALSE, 1000); cld = rv - WAIT_OBJECT_0; if (rv == WAIT_TIMEOUT) { apr_proc_other_child_refresh_all(APR_OC_REASON_RUNNING); @@ -1136,6 +1146,13 @@ void child_main(apr_pool_t *pconf) "ending."); break; } + else if (cld == 2) { + /* The parent is dead. Shutdown the child process. */ + ap_log_error(APLOG_MARK, APLOG_CRIT, 0, ap_server_conf, APLOGNO(02538) + "Child: Parent process exited abruptly. Child process " + "is ending"); + break; + } else { /* MaxConnectionsPerChild event set by the worker threads. * Signal the parent to restart diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 8b7a2fc478..e532dac923 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -1708,7 +1708,7 @@ static int winnt_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, ap_server_conf, APLOGNO(00453) "Child process is running"); - child_main(pconf); + child_main(pconf, parent_pid); ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, ap_server_conf, APLOGNO(00454) "Child process is exiting"); diff --git a/server/mpm/winnt/mpm_winnt.h b/server/mpm/winnt/mpm_winnt.h index 8e13748447..0c7a385d7a 100644 --- a/server/mpm/winnt/mpm_winnt.h +++ b/server/mpm/winnt/mpm_winnt.h @@ -92,7 +92,7 @@ AP_DECLARE(void) ap_signal_parent(ap_signal_parent_e type); void hold_console_open_on_error(void); /* From child.c: */ -void child_main(apr_pool_t *pconf); +void child_main(apr_pool_t *pconf, DWORD parent_pid); apr_status_t winnt_insert_network_bucket(conn_rec *c, apr_bucket_brigade *bb, apr_socket_t *socket);