]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Add ap_append_pid(); This is performed enough to warrant
authorJim Jagielski <jim@apache.org>
Wed, 31 Aug 2005 15:22:08 +0000 (15:22 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 31 Aug 2005 15:22:08 +0000 (15:22 +0000)
a function I think, especially with the fact that
the mapping of getpid() to APR_PID_T_FMT isn't
consistant in some areas.

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

include/httpd.h
modules/generators/mod_cgid.c
modules/loggers/mod_log_config.c
server/mpm/prefork/prefork.c
server/util.c

index 7b02cd150938d23731c40ce734dc2cd1bb3c8970..7f08b92d1dd39d9ae833634d4c5392ca36236356 100644 (file)
@@ -1681,6 +1681,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 2c2368b9e797cbc8634b53260330541f7215cf73..47971393c5726d6f1c27c88de15ce1863a6cc7e8 100644 (file)
@@ -812,8 +812,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 = apr_psprintf(pconf, "%s.%" APR_PID_T_FMT, DEFAULT_SOCKET, 
-                            getpid());
+    sockname = ap_append_pid(pconf, DEFAULT_SOCKET, ".");
     return OK;
 }
 
@@ -929,7 +928,7 @@ static const char *set_script_socket(cmd_parms *cmd, void *dummy, const char *ar
     }
     
     /* Make sure the pid is appended to the sockname */
-    sockname = apr_psprintf(cmd->pool, "%s.%" APR_PID_T_FMT, arg, getpid());
+    sockname = ap_append_pid(cmd->pool, arg, ".");
     sockname = ap_server_root_relative(cmd->pool, sockname); 
 
     if (!sockname) {
index 718441d7141b7d99c52225e1eb539b9e742634b4..268096ff58c310fcdcd2c1e595491f5c0067a4ff 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") || !strcmp(a, "hextid")) {
 #if APR_HAS_THREADS
index 1198a6cb2302674521373a552e3eb388483eda70..b9b4ab96ecb931fb78a01026b3a523ea3dd2230d 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());
+
+}