]> granicus.if.org Git - apache/commitdiff
Fix a mod_cgid problem that left daemon processes stranded
authorJeff Trawick <trawick@apache.org>
Fri, 22 Mar 2002 02:56:56 +0000 (02:56 +0000)
committerJeff Trawick <trawick@apache.org>
Fri, 22 Mar 2002 02:56:56 +0000 (02:56 +0000)
in some server restart scenarios.

It relied on getting SIGHUP to die, but it wasn't careful
about establishing the SIGHUP handling it needed so after
apachectl restart, SIGHUP was ignored since the new cgid
daemon process inherited a signal(SIGHUP,SIG_IGN) done by
the MPM during its restart logic.

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

CHANGES
modules/generators/mod_cgid.c

diff --git a/CHANGES b/CHANGES
index e77eb439b41007cd192ec693872c2803bbe3f7c1..a5dfd288e8284039e6ed923ae92f98cf80682200 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
 Changes with Apache 2.0.34-dev
 
+  *) Fix a mod_cgid problem that left daemon processes stranded
+     in some server restart scenarios.  [Jeff Trawick]
+
   *) Added exp_foo and rel_foo variables to config_vars.mk for
      all Apache and Autoconf path variables (like --sysconfdir,
      --sbindir, etc). exp_foo is the "expanded" version, which means
index 07bbc4d354046108e55c4a5219dba7da43d87f2b..52994e03c31af7f650c0f37dfd6e165cef0e709c 100644 (file)
@@ -128,6 +128,7 @@ static APR_OPTIONAL_FN_TYPE(ap_ssi_parse_string) *cgid_pfn_ps;
 static apr_pool_t *pcgi; 
 static int total_modules = 0;
 static pid_t daemon_pid;
+static int daemon_should_exit = 0;
 
 /* KLUDGE --- for back-combatibility, we don't have to check Execcgid 
  * in ScriptAliased directories, which means we need to know if this 
@@ -256,7 +257,7 @@ static void cgid_maint(int reason, void *data, apr_wait_t status)
             /* we get here when pcgi is cleaned up; pcgi gets cleaned
              * up when pconf gets cleaned up
              */
-            kill(*sd, SIGHUP);
+            kill(*sd, SIGHUP); /* send signal to daemon telling it to die */
             break;
     }
 }
@@ -481,6 +482,13 @@ static void send_req(int fd, request_rec *r, char *argv0, char **env, int req_ty
 #endif 
 } 
 
+static void daemon_signal_handler(int sig)
+{
+    if (sig == SIGHUP) {
+        ++daemon_should_exit;
+    }
+}
+
 static int cgid_server(void *data) 
 { 
     struct sockaddr_un unix_addr;
@@ -495,6 +503,8 @@ static int cgid_server(void *data)
     apr_pool_create(&ptrans, pcgi); 
 
     apr_signal(SIGCHLD, SIG_IGN); 
+    apr_signal(SIGHUP, daemon_signal_handler);
+
     if (unlink(sconf->sockname) < 0 && errno != ENOENT) {
         ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
                      "Couldn't unlink unix domain socket %s",
@@ -538,7 +548,8 @@ static int cgid_server(void *data)
     }
     
     unixd_setup_child(); /* if running as root, switch to configured user/group */
-    while (1) {
+
+    while (!daemon_should_exit) {
         int errfileno = STDERR_FILENO;
         char *argv0; 
         char **env; 
@@ -659,6 +670,7 @@ static int cgid_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         for (m = ap_preloaded_modules; *m != NULL; m++)
             total_modules++;
 
+        daemon_should_exit = 0; /* clear setting from previous generation */
         if ((daemon_pid = fork()) < 0) {
             ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, 
                          "Couldn't spawn cgid daemon process");