]> granicus.if.org Git - apache/commitdiff
Merge r1822537, r1830744 from trunk:
authorYann Ylavic <ylavic@apache.org>
Wed, 6 Jun 2018 10:53:16 +0000 (10:53 +0000)
committerYann Ylavic <ylavic@apache.org>
Wed, 6 Jun 2018 10:53:16 +0000 (10:53 +0000)
mpm_unix(es): cleanup properly on exit in one_process mode.

We can't destroy ap_pglobal in the MPMs because clean_child_exit() runs in
a DSO which would be unloaded under us.

So we defer an ap_terminate() with atexit() in ap_unixd_mpm_set_signals(),
all this is static/builtin code in "os/unix/unixd.c".

Follow up to r1822537: replace static variable with pool userdata.

Also adds a comment and a CHANGES entry.

Submitted by: ylavic
Reviewed by: ylavic, jim, icing

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1833005 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
os/unix/unixd.c

diff --git a/CHANGES b/CHANGES
index 2aeebb116660218cdca5f07285baf00577f2aa0b..b9bbc876b96d49f2272265619e23809466a9e0d9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.4.34
 
+  *) core: In ONE_PROCESS/debug mode, cleanup everything when exiting.
+     [Yann Ylavic]
+
   *) mod_proxy_balancer: Add hot spare member type and corresponding flag (R).
      Hot spare members are used as drop-in replacements for unusable workers
      in the same load balancer set. This differs from hot standbys which are
index 43645f09daf803d1d735f73a5b293417c7a2d2e5..0245720aa07062253120f484c8f477ef4d909af3 100644 (file)
@@ -18,6 +18,7 @@
 #include "httpd.h"
 #include "http_config.h"
 #include "http_main.h"
+#include "http_core.h"
 #include "http_log.h"
 #include "unixd.h"
 #include "mpm_common.h"
@@ -509,6 +510,13 @@ static apr_status_t unset_signals(void *unused)
     return APR_SUCCESS;
 }
 
+static void ap_terminate(void)
+{
+    ap_main_state = AP_SQ_MS_EXITING;
+    apr_pool_destroy(ap_pglobal);
+    apr_terminate();
+}
+
 AP_DECLARE(void) ap_unixd_mpm_set_signals(apr_pool_t *pconf, int one_process)
 {
 #ifndef NO_USE_SIGACTION
@@ -518,6 +526,16 @@ AP_DECLARE(void) ap_unixd_mpm_set_signals(apr_pool_t *pconf, int one_process)
     if (!one_process) {
         ap_fatal_signal_setup(ap_server_conf, pconf);
     }
+    else if (!ap_retained_data_get("ap_unixd_mpm_one_process_cleanup")) {
+        /* In one process mode (debug), httpd will exit immediately when asked
+         * to (SIGTERM/SIGINT) and never restart. We still want the cleanups to
+         * run though (such that e.g. temporary files/IPCs don't leak on the
+         * system), so the first time around we use atexit() to cleanup after
+         * ourselves.
+         */
+        ap_retained_data_create("ap_unixd_mpm_one_process_cleanup", 1);
+        atexit(ap_terminate);
+    }
 
     /* Signals' handlers depend on retained data */
     (void)ap_unixd_mpm_get_retained_data();