]> granicus.if.org Git - apache/commitdiff
Retain signal handling in the worker MPM for the one_process case
authorAaron Bannert <aaron@apache.org>
Thu, 14 Feb 2002 02:48:19 +0000 (02:48 +0000)
committerAaron Bannert <aaron@apache.org>
Thu, 14 Feb 2002 02:48:19 +0000 (02:48 +0000)
(httpd with -DDEBUG, -X, or -DONE_PROCESS).

Fix -X, -DNO_DETACH, -DONE_PROCESS, etc. flags.

Tested on solaris w/ start/stop, restart, graceful, and with the
above debugging flags.

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

server/mpm/worker/worker.c

index 5cd3bfabf6c442d4ab51db840b739ef1da086800..f571fb63cc6134d008538b530553c3a481fe1734 100644 (file)
@@ -680,6 +680,12 @@ static void *listener_thread(apr_thread_t *thd, void * dummy)
             apr_pool_tag(ptrans, "transaction");
             rv = lr->accept_func(&csd, lr, ptrans);
 
+            /* If we were interrupted for whatever reason, just start
+             * the main loop over again. (The worker MPM still uses
+             * signals in the one_process case.) */
+            if (APR_STATUS_IS_EINTR(rv)) {
+                continue;
+            }
             if (rv == APR_EGENERAL) {
                 /* E[NM]FILE, ENOMEM, etc */
                 resource_shortage = 1;
@@ -770,6 +776,16 @@ static void * APR_THREAD_FUNC worker_thread(apr_thread_t *thd, void * dummy)
     return NULL;
 }
 
+static int check_signal(int signum)
+{
+    switch (signum) {
+    case SIGTERM:
+    case SIGINT:
+        return 1;
+    }
+    return 0;
+}
+
 static void * APR_THREAD_FUNC start_threads(apr_thread_t *thd, void *dummy)
 {
     thread_starter *ts = dummy;
@@ -951,22 +967,21 @@ static void child_main(int child_num_arg)
         clean_child_exit(APEXIT_CHILDFATAL);
     }
 
-    /* Watch for any messages from the parent over the POD */
-    while (1) {
-        rv = ap_mpm_pod_check(pod);
-        if (rv == AP_GRACEFUL || rv == AP_RESTART) {
-            signal_workers();
-            break;
-        }
-    }
-
-    if (rv == AP_GRACEFUL) {
-        /* A terminating signal was received. Now join each of the workers to 
-         * clean them up.
-         *   If the worker already exited, then the join frees their resources 
-         *   and returns.
-         *   If the worker hasn't exited, then this blocks until they have (then
-         *   cleans up).
+    /* If we are only running in one_process mode, we will want to
+     * still handle signals. */
+    if (one_process) {
+        /* Set up a signal handler for this thread. */
+        apr_signal_thread(check_signal);
+        signal_workers(); /* helps us terminate a little more quickly when
+                           * the dispatch of the signal thread
+                           * beats the Pipe of Death and the browsers
+                           */
+        /* A terminating signal was received. Now join each of the
+         * workers to clean them up.
+         *   If the worker already exited, then the join frees
+         *   their resources and returns.
+         *   If the worker hasn't exited, then this blocks until
+         *   they have (then cleans up).
          */
         apr_thread_join(&rv, start_thread_id);
         for (i = 0; i < ap_threads_per_child; i++) {
@@ -975,6 +990,32 @@ static void child_main(int child_num_arg)
             }
         }
     }
+    else { /* !one_process */
+        /* Watch for any messages from the parent over the POD */
+        while (1) {
+            rv = ap_mpm_pod_check(pod);
+            if (rv == AP_GRACEFUL || rv == AP_RESTART) {
+                signal_workers();
+                break;
+            }
+        }
+
+        if (rv == AP_GRACEFUL) {
+            /* A terminating signal was received. Now join each of the
+             * workers to clean them up.
+             *   If the worker already exited, then the join frees
+             *   their resources and returns.
+             *   If the worker hasn't exited, then this blocks until
+             *   they have (then cleans up).
+             */
+            apr_thread_join(&rv, start_thread_id);
+            for (i = 0; i < ap_threads_per_child; i++) {
+                if (threads[i]) { /* if we ever created this thread */
+                    apr_thread_join(&rv, threads[i]);
+                }
+            }
+        }
+    }
 
     free(threads);
 
@@ -1453,10 +1494,12 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         return DONE;
     }
 
-    if ((rv = ap_mpm_pod_open(pconf, &pod))) {
-        ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL,
-                "Could not open pipe-of-death.");
-        return DONE;
+    if (!one_process) {
+        if ((rv = ap_mpm_pod_open(pconf, &pod))) {
+            ap_log_error(APLOG_MARK, APLOG_CRIT|APLOG_STARTUP, rv, NULL,
+                    "Could not open pipe-of-death.");
+            return DONE;
+        }
     }
     return OK;
 }