]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
* core/mpm: add hook 'child_stopping` that gets called when the MPM is
authorStefan Eissing <icing@apache.org>
Sat, 31 Jul 2021 13:36:19 +0000 (13:36 +0000)
committerStefan Eissing <icing@apache.org>
Sat, 31 Jul 2021 13:36:19 +0000 (13:36 +0000)
    stopping a child process. The additional `graceful` parameter allows
    registered hooks to free resources early during a graceful shutdown.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1891919 13f79535-47bb-0310-9956-ffa450edef68

changes-entries/core_child_stopping.txt [new file with mode: 0644]
include/ap_mmn.h
include/mpm_common.h
server/mpm/event/event.c
server/mpm/prefork/prefork.c
server/mpm/worker/worker.c
server/mpm_common.c

diff --git a/changes-entries/core_child_stopping.txt b/changes-entries/core_child_stopping.txt
new file mode 100644 (file)
index 0000000..c85230e
--- /dev/null
@@ -0,0 +1,4 @@
+  * core/mpm: add hook 'child_stopping` that gets called when the MPM is
+    stopping a child process. The additional `graceful` parameter allows
+    registered hooks to free resources early during a graceful shutdown.
+    [Yann Ylavic, Stefan Eissing]
index 57166bae134fb8e87f2dac105a0e733975079436..126c7e6c95bc411abcb7c7ff0f0e804aaffa1339 100644 (file)
  *                         ap_bucket_wc_create() to util_filter.h
  * 20210531.2 (2.5.1-dev)  Add ap_proxy_get_worker_ex() and
  *                         ap_proxy_define_worker_ex() to mod_proxy.h
+ * 20210531.3 (2.5.1-dev)  Add hook child_stopping to get informed that a child
+ *                         is being shut down.
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
index a8e7b03749df3188ecc57705d6f72d7a62e4fe1f..007a24a498edb496a74a7ea41f9e888cc27a6dda 100644 (file)
@@ -511,6 +511,15 @@ AP_DECLARE_HOOK(void, suspend_connection,
 AP_DECLARE_HOOK(void, resume_connection,
                 (conn_rec *c, request_rec *r))
 
+/**
+ * Notification that the child is stopping. If graceful, ongoing
+ * requests will be served.
+ * @param pchild The child pool
+ * @param graceful != 0 iff this is a graceful shutdown.
+ */
+AP_DECLARE_HOOK(void, child_stopping,
+                (apr_pool_t *pchild, int graceful))
+
 /* mutex type string for accept mutex, if any; MPMs should use the
  * same mutex type for ease of configuration
  */
index 24a90c818bfd0f01df58b491af2226fd83018ca3..1a27a8fc576620a85e56522177a1be2605ad9c49 100644 (file)
@@ -659,6 +659,8 @@ static void signal_threads(int mode)
         ap_queue_interrupt_all(worker_queue);
         close_worker_sockets(); /* forcefully kill all current connections */
     }
+
+    ap_run_child_stopping(pchild, mode == ST_GRACEFUL);
 }
 
 static int event_query(int query_code, int *result, apr_status_t *rv)
@@ -758,6 +760,10 @@ static void clean_child_exit(int code) __attribute__ ((noreturn));
 static void clean_child_exit(int code)
 {
     retained->mpm->mpm_state = AP_MPMQ_STOPPING;
+    if (terminate_mode == ST_INIT) {
+        ap_run_child_stopping(pchild, 0);
+    }
+
     if (pchild) {
         apr_pool_destroy(pchild);
     }
index 4cef7b6c567655c81ec90d6f2ce1d03a70ea62e1..447b901ed8f9dc684754e534ad1634935b7def7b 100644 (file)
@@ -219,11 +219,14 @@ static void prefork_note_child_started(int slot, pid_t pid)
 static void clean_child_exit(int code) __attribute__ ((noreturn));
 static void clean_child_exit(int code)
 {
-    retained->mpm->mpm_state = AP_MPMQ_STOPPING;
-
     apr_signal(SIGHUP, SIG_IGN);
     apr_signal(SIGTERM, SIG_IGN);
 
+    retained->mpm->mpm_state = AP_MPMQ_STOPPING;
+    if (code == 0) {
+        ap_run_child_stopping(pchild, 0);
+    }
+
     if (pchild) {
         apr_pool_destroy(pchild);
         /*
index 94c47ef755983363997cecbc1e17a9907317a406..cf1837239e6b05d18427677b780b7661cfd2c196 100644 (file)
@@ -325,6 +325,8 @@ static void signal_threads(int mode)
         ap_queue_interrupt_all(worker_queue);
         close_worker_sockets(); /* forcefully kill all current connections */
     }
+
+    ap_run_child_stopping(pchild, mode == ST_GRACEFUL);
 }
 
 static int worker_query(int query_code, int *result, apr_status_t *rv)
@@ -433,6 +435,10 @@ static void clean_child_exit(int code) __attribute__ ((noreturn));
 static void clean_child_exit(int code)
 {
     retained->mpm->mpm_state = AP_MPMQ_STOPPING;
+    if (terminate_mode == ST_INIT) {
+        ap_run_child_stopping(pchild, 0);
+    }
+
     if (pchild) {
         apr_pool_destroy(pchild);
     }
index d5a27faa0413c04723260f67d43877f7e5a1dd26..4b8c41e67cb0fdecef5a58a33888d185d4a8c1f2 100644 (file)
@@ -77,7 +77,8 @@
     APR_HOOK_LINK(output_pending) \
     APR_HOOK_LINK(input_pending) \
     APR_HOOK_LINK(suspend_connection) \
-    APR_HOOK_LINK(resume_connection)
+    APR_HOOK_LINK(resume_connection) \
+    APR_HOOK_LINK(child_stopping)
 
 #if AP_ENABLE_EXCEPTION_HOOK
 APR_HOOK_STRUCT(
@@ -136,6 +137,9 @@ AP_IMPLEMENT_HOOK_VOID(suspend_connection,
 AP_IMPLEMENT_HOOK_VOID(resume_connection,
                        (conn_rec *c, request_rec *r),
                        (c, r))
+AP_IMPLEMENT_HOOK_VOID(child_stopping,
+                       (apr_pool_t *pchild, int graceful),
+                       (pchild, graceful))
 
 /* hooks with no args are implemented last, after disabling APR hook probes */
 #if defined(APR_HOOK_PROBES_ENABLED)