]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Append the .PID to the ScriptSock filename. This change ensures that multiple
authorColm MacCarthaigh <colm@apache.org>
Thu, 25 Aug 2005 11:51:24 +0000 (11:51 +0000)
committerColm MacCarthaigh <colm@apache.org>
Thu, 25 Aug 2005 11:51:24 +0000 (11:51 +0000)
running instances of httpd will not clobber each others script sockets.

Because a different socket will be created for each instance, this change also
unlinks the script-socket on exit, to prevent pollution.

unlink() happens from within the parent process, since the change in userid's
means the cgid process likely won't have the correct permissions.

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

CHANGES
modules/generators/mod_cgid.c

diff --git a/CHANGES b/CHANGES
index 16e1c8bed28bdaeeedd27403c5a1aba72f8dbc61..e30da9b75febff0cbc717a33499104b19853ab6d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
 Changes with Apache 2.3.0
   [Remove entries to the current 2.0 and 2.2 section below, when backported]
 
+  *) mod_cgid: Append .PID to the script socket filename and remove the
+     script socket on exit. [Colm MacCarthaigh]
+
   *) prefork and worker MPM's: Prevent children from holding open listening
      ports upon graceful restart. PR28167. 
      [Colm MacCarthaigh, Brian Pinkerton <bp thinkpink.com>]
index 72f60ef50b562a411f42e9113987fb895cf857b1..013b2010766f9b76d273363d7f834309eacd6724 100644 (file)
@@ -268,6 +268,15 @@ static void cgid_maint(int reason, void *data, apr_wait_t status)
              * up when pconf gets cleaned up
              */
             kill(proc->pid, SIGHUP); /* send signal to daemon telling it to die */
+
+            /* Remove the cgi socket, we must do it here in order to try and
+             * guarantee the same permissions as when the socket was created.
+             */
+            if (unlink(sockname) < 0 && errno != ENOENT) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, errno, NULL,
+                             "Couldn't unlink unix domain socket %s",
+                             sockname);
+            }
             break;
     }
 }
@@ -582,13 +591,6 @@ static int cgid_server(void *data)
     apr_signal(SIGCHLD, SIG_IGN); 
     apr_signal(SIGHUP, daemon_signal_handler);
 
-    if (unlink(sockname) < 0 && errno != ENOENT) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
-                     "Couldn't unlink unix domain socket %s",
-                     sockname);
-        /* just a warning; don't bail out */
-    }
-
     if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
         ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server, 
                      "Couldn't create unix domain socket");
@@ -818,7 +820,8 @@ static int cgid_start(apr_pool_t *p, server_rec *main_server,
 static int cgid_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
                            apr_pool_t *ptemp)
 {
-    sockname = DEFAULT_SOCKET;
+    sockname = apr_psprintf(pconf, "%s.%" APR_PID_T_FMT, DEFAULT_SOCKET, 
+                            getpid());
     return OK;
 }
 
@@ -932,8 +935,10 @@ static const char *set_script_socket(cmd_parms *cmd, void *dummy, const char *ar
     if (err != NULL) {
         return err;
     }
-
-    sockname = ap_server_root_relative(cmd->pool, arg); 
+    
+    /* Make sure the pid is appended to the sockname */
+    sockname = apr_psprintf(cmd->pool, "%s.%" APR_PID_T_FMT, arg, getpid());
+    sockname = ap_server_root_relative(cmd->pool, sockname); 
 
     if (!sockname) {
         return apr_pstrcat(cmd->pool, "Invalid ScriptSock path",