]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Backport r265506, r240044 and r240049 to the 2.2.x branch; Appends .PID to the
authorColm MacCarthaigh <colm@apache.org>
Sun, 18 Sep 2005 20:39:34 +0000 (20:39 +0000)
committerColm MacCarthaigh <colm@apache.org>
Sun, 18 Sep 2005 20:39:34 +0000 (20:39 +0000)
ScriptSock filename.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@289972 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/mod/mod_cgid.xml
include/httpd.h
modules/generators/mod_cgid.c
modules/loggers/mod_log_config.c
server/mpm/prefork/prefork.c
server/util.c

diff --git a/CHANGES b/CHANGES
index a2aeac6c73e9de914c9b6130015f5e90a8ce9aa8..851dc2dbbb0ee2228747e05d0e33e6797dc4c47a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                         -*- coding: utf-8 -*-
 Changes with Apache 2.1.8
 
+  *) mod_cgid: Append .PID to the script socket filename and remove the
+     script socket on exit. [Colm MacCarthaigh, Jim Jagielski]
+
   *) mod_cgid: run the get_suexec_identity hook within the request-handler 
      instead of within cgid. PR 36410. [Colm MacCarthaigh]
 
index 1d6c85aa5d2dbb31f0a0d9b5bab017388c4b4fc2..93199555689c3207ebf69e9eb982870b29b4e59c 100644 (file)
@@ -74,7 +74,7 @@
 
 <directivesynopsis>
 <name>ScriptSock</name>
-<description>The name of the socket to use for communication with
+<description>The filename prefix of the socket to use for communication with
 the cgi daemon</description>
 <syntax>ScriptSock <var>file-path</var></syntax>
 <default>ScriptSock logs/cgisock</default>
@@ -82,8 +82,9 @@ the cgi daemon</description>
 <context>virtual host</context></contextlist>
 
 <usage>
-    <p>This directive sets the name of the socket to use for
-    communication with the CGI daemon. The socket will be opened
+    <p>This directive sets the filename prefix of the socket to use for
+    communication with the CGI daemon, an extension correspondening to
+    the process ID of the server will be appended. The socket will be opened
     using the permissions of the user who starts Apache (usually
     root). To maintain the security of communications with CGI
     scripts, it is important that no other user has permission to
index 761a612b6a3ae494cc02b32e402a78825d602346..406fd08f7b3a71b8693f1740d69a22bdfbd1ad1a 100644 (file)
@@ -1610,6 +1610,19 @@ AP_DECLARE(int) ap_rind(const char *str, char c);
  */
 AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring);
 
+/**
+ * Given a string, append the PID deliminated by delim.
+ * Usually used to create a pid-appended filepath name
+ * (eg: /a/b/foo -> /a/b/foo.6726). A function, and not
+ * a macro, to avoid unistd.h dependency
+ * @param p The pool to allocate memory from
+ * @param string The string to append the PID to
+ * @param delim The string to use to deliminate the string from the PID
+ * @return A copy of the string with the PID appended 
+ */
+AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string,
+                                 const char *delim);
+
 /* Misc system hackery */
 /**
  * Given the name of an object in the file system determine if it is a directory
index a25c89c6b2ea62319356bc9efc2ac6a774bc1702..1299f4c45daf0fffb16edfc5c66df54913dd695d 100644 (file)
@@ -275,6 +275,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;
     }
 }
@@ -557,13 +566,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 */
-    }
-
     /* cgid should use its own suexec doer */
     ap_hook_get_suexec_identity(cgid_suexec_id_doer, NULL, NULL,
                                 APR_HOOK_REALLY_FIRST);
@@ -807,7 +809,7 @@ 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 = ap_append_pid(pconf, DEFAULT_SOCKET, ".");
     return OK;
 }
 
@@ -922,7 +924,8 @@ static const char *set_script_socket(cmd_parms *cmd, void *dummy, const char *ar
         return err;
     }
 
-    sockname = ap_server_root_relative(cmd->pool, arg); 
+    sockname = ap_append_pid(cmd->pool, arg, ".");
+    sockname = ap_server_root_relative(cmd->pool, sockname); 
 
     if (!sockname) {
         return apr_pstrcat(cmd->pool, "Invalid Scriptsock path",
index b8900683e60926982045030b61be7b82253e86fb..b0d7ec8c0b836c5929ed5cf1ac5715919de31e69 100644 (file)
@@ -648,7 +648,7 @@ static const char *log_server_name(request_rec *r, char *a)
 static const char *log_pid_tid(request_rec *r, char *a)
 {
     if (*a == '\0' || !strcmp(a, "pid")) {
-        return apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid());
+        return ap_append_pid(r->pool, "", "");
     }
     else if (!strcmp(a, "tid")) {
 #if APR_HAS_THREADS
index 0afe6f0bdde10267670001425ad015de9f61582d..8776f32616e95e5d696a7e49a64febff94b0db86 100644 (file)
@@ -156,16 +156,13 @@ static void chdir_for_gprof(void)
 
     if(dir) {
         apr_status_t res;
-        char buf[512];
+        char * buf = NULL;
         int len = strlen(sconf->gprof_dir) - 1;
         if(*(dir + len) == '%') {
             dir[len] = '\0';
-            apr_snprintf(buf, sizeof(buf), "%sgprof.%d", dir, (int)getpid());
+            buf = ap_append_pid(pconf, dir, "gprof.");
         }
-        else {
-            buf[0] = '\0';
-        }
-        use_dir = ap_server_root_relative(pconf, buf[0] ? buf : dir);
+        use_dir = ap_server_root_relative(pconf, buf ? buf : dir);
         res = apr_dir_make(use_dir,
                            APR_UREAD | APR_UWRITE | APR_UEXECUTE |
                            APR_GREAD | APR_GEXECUTE |
index 34d7ce51ae382d5ef5c1b7b01c270f0d28f102e5..10c647629805aeb94521ed0a524afcc30879f0c9 100644 (file)
@@ -2128,3 +2128,17 @@ AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring)
     *outchr = '\0';
     return outstring;
 }
+
+/*
+ * Given a string, append the PID deliminated by delim.
+ * Usually used to create a pid-appended filepath name
+ * (eg: /a/b/foo -> /a/b/foo.6726). A function, and not
+ * a macro, to avoid unistd.h dependency
+ */
+AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string,
+                                    const char *delim)
+{
+    return apr_psprintf(p, "%s%s%" APR_PID_T_FMT, string,
+                        delim, getpid());
+
+}