]> granicus.if.org Git - apache/commitdiff
WinNT MPM: Exit the child if the parent process crashes or is terminated.
authorJeff Trawick <trawick@apache.org>
Thu, 26 Sep 2013 20:08:33 +0000 (20:08 +0000)
committerJeff Trawick <trawick@apache.org>
Thu, 26 Sep 2013 20:08:33 +0000 (20:08 +0000)
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

CHANGES
docs/log-message-tags/next-number
server/mpm/winnt/child.c
server/mpm/winnt/mpm_winnt.c
server/mpm/winnt/mpm_winnt.h

diff --git a/CHANGES b/CHANGES
index 11a9d26ff2345b17d76b370a5df31d44db3cc9b8..88c80a88c0249a6f04bf253461147a7b042ca2f3 100644 (file)
--- 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]
 
index 1232cc3bd2c42ee45830dfcf597765e749590072..166c7ce5e94432a6ad7486892c6b364d5e631492 100644 (file)
@@ -1 +1 @@
-2538
+2539
index cb37fc9f3aeb8a8010d10929facf9957e1d874c6..49b5c2be66efd3f2d76bc6252ac3b61b99940431 100644 (file)
@@ -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
index 8b7a2fc4781f937208a7a0ca6193f3f360e88f2e..e532dac9231538a563a0f556cf6715c195f0db81 100644 (file)
@@ -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");
index 8e1374844705a3a4d0e4e18e8407d8e46ed19a47..0c7a385d7a2c2bd440e2a31cafecb155f5d6e6e9 100644 (file)
@@ -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);