]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mpm_prefork: mask signals during ap_run_child_init().
authorYann Ylavic <ylavic@apache.org>
Fri, 4 Jun 2021 13:21:28 +0000 (13:21 +0000)
committerYann Ylavic <ylavic@apache.org>
Fri, 4 Jun 2021 13:21:28 +0000 (13:21 +0000)
This prevents threads potentially created from the child_init hooks (e.g.
mod_watchdog workers) to catch signals needed by the MPM, like here:
https://travis-ci.com/github/apache/httpd/jobs/510821148#L5356.

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

changes-entries/prefork_child_init_sigmask.txt [new file with mode: 0644]
docs/log-message-tags/next-number
server/mpm/prefork/prefork.c

diff --git a/changes-entries/prefork_child_init_sigmask.txt b/changes-entries/prefork_child_init_sigmask.txt
new file mode 100644 (file)
index 0000000..16c2eb2
--- /dev/null
@@ -0,0 +1,3 @@
+  *) mpm_prefork: Block signals for child_init hooks to prevent potential
+     threads created from there to catch MPM's signals.
+     [Ruediger Pluem, Yann Ylavic]
index 2c3ed9dc19578a4d1215c3528980e2bb352db4d5..d36fd9c9126d8c123c5668ebbd3832ed50a2b6a2 100644 (file)
@@ -1 +1 @@
-10271
+10272
index 51d5211bd01976a24b32d1a4875586319d0683c4..4cef7b6c567655c81ec90d6f2ce1d03a70ea62e1 100644 (file)
@@ -382,11 +382,23 @@ static void stop_listening(int sig)
 static int requests_this_child;
 static int num_listensocks = 0;
 
+#if APR_HAS_THREADS
+static void child_sigmask(sigset_t *new_mask, sigset_t *old_mask)
+{
+#if defined(SIGPROCMASK_SETS_THREAD_MASK)
+    sigprocmask(SIG_SETMASK, new_mask, old_mask);
+#else
+    pthread_sigmask(SIG_SETMASK, new_mask, old_mask);
+#endif
+}
+#endif
+
 static void child_main(int child_num_arg, int child_bucket)
 {
 #if APR_HAS_THREADS
     apr_thread_t *thd = NULL;
     apr_os_thread_t osthd;
+    sigset_t sig_mask;
 #endif
     apr_pool_t *ptrans;
     apr_allocator_t *allocator;
@@ -452,8 +464,31 @@ static void child_main(int child_num_arg, int child_bucket)
         clean_child_exit(APEXIT_CHILDFATAL);
     }
 
+#if APR_HAS_THREADS
+    /* Save the signal mask and block all the signals from being received by
+     * threads potentially created in child_init() hooks (e.g. mod_watchdog).
+     */
+    child_sigmask(NULL, &sig_mask);
+    {
+        apr_status_t rv;
+        rv = apr_setup_signal_thread();
+        if (rv != APR_SUCCESS) {
+            ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf, APLOGNO(10271)
+                         "Couldn't initialize signal thread");
+            clean_child_exit(APEXIT_CHILDFATAL);
+        }
+    }
+#endif /* APR_HAS_THREADS */
+
     ap_run_child_init(pchild, ap_server_conf);
 
+#if APR_HAS_THREADS
+    /* Restore the original signal mask for this main thread, the only one
+     * that should possibly get interrupted by signals.
+     */
+    child_sigmask(&sig_mask, NULL);
+#endif
+
     ap_create_sb_handle(&sbh, pchild, my_child_num, 0);
 
     (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL);