]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
consolidate logic to remove the pidfile in a new API,
authorJeff Trawick <trawick@apache.org>
Mon, 28 Mar 2011 13:35:08 +0000 (13:35 +0000)
committerJeff Trawick <trawick@apache.org>
Mon, 28 Mar 2011 13:35:08 +0000 (13:35 +0000)
ap_remove_pid(), related to existing ap_log_pid() and
ap_read_pid()

presumably this is useful to third-party MPMs as well

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

CHANGES
include/http_log.h
server/log.c
server/mpm/event/event.c
server/mpm/mpmt_os2/mpmt_os2.c
server/mpm/prefork/prefork.c
server/mpm/winnt/mpm_winnt.c
server/mpm/worker/worker.c

diff --git a/CHANGES b/CHANGES
index be2eee6e2f2732e2773e346718bf035ee0996cce..e0ee0ded53b57abcfd9bdb4b4aed1f77b6ec6182 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
 
 Changes with Apache 2.3.12
 
+  *) MPM helper function ap_remove_pid() added.  [Jeff Trawick]
+
   *) Enable DEFAULT_REL_RUNTIMEDIR on Windows and NetWare.  [various]
 
   *) Correct C++ incompatibility with http_log.h.  [Stefan Fritsch, Jeff
index d635ab1cf255c45b44da8eb1e1a08c65bf5d3731..f2aa4c7fd7dc6abf954fe29365f597f718c0faf5 100644 (file)
@@ -560,14 +560,21 @@ AP_DECLARE(void) ap_log_command_line(apr_pool_t *p, server_rec *s);
 
 /**
  * Log the current pid of the parent process
- * @param p The pool to use for logging
+ * @param p The pool to use for processing
  * @param fname The name of the file to log to
  */
 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname);
 
+/**
+ * Remove the pidfile.
+ * @param p The pool to use for processing
+ * @param fname The name of the pid file to remove
+ */
+AP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *fname);
+
 /**
  * Retrieve the pid from a pidfile.
- * @param p The pool to use for logging
+ * @param p The pool to use for processing
  * @param filename The name of the file containing the pid
  * @param mypid Pointer to pid_t (valid only if return APR_SUCCESS)
  */
index 4f7bf081b6a1a97c9a6ede17b212d30843953f4b..50d9cbcb3ede20e6fef25e00f321ee94ac19fc86 100644 (file)
@@ -1361,6 +1361,25 @@ AP_DECLARE(void) ap_log_command_line(apr_pool_t *plog, server_rec *s)
                  "Command line: '%s'", result);
 }
 
+AP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *rel_fname)
+{
+    apr_status_t rv;
+    const char *fname = ap_server_root_relative(p, rel_fname);
+
+    if (fname != NULL) {
+        rv = apr_file_remove(fname, p);
+        if (rv != APR_SUCCESS) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf,
+                         "failed to remove PID file %s", fname);
+        }
+        else {
+            ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
+                         "removed PID file %s (pid=%" APR_PID_T_FMT ")",
+                         fname, getpid());
+        }
+    }
+}
+
 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename)
 {
     apr_file_t *pid_file = NULL;
index 4b0cf39e619e713fc5699929ace08ac897b6f9bf..81c2ba86953f315891acd004bb560c6d0133e85d 100644 (file)
@@ -2260,14 +2260,7 @@ static int event_run(apr_pool_t * _pconf, apr_pool_t * plog, server_rec * s)
 
         if (!child_fatal) {
             /* cleanup pid file on normal shutdown */
-            const char *pidfile = NULL;
-            pidfile = ap_server_root_relative(pconf, ap_pid_fname);
-            if (pidfile != NULL && unlink(pidfile) == 0)
-                ap_log_error(APLOG_MARK, APLOG_INFO, 0,
-                             ap_server_conf,
-                             "removed PID file %s (pid=%ld)",
-                             pidfile, (long) getpid());
-
+            ap_remove_pid(pconf, ap_pid_fname);
             ap_log_error(APLOG_MARK, APLOG_NOTICE, 0,
                          ap_server_conf, "caught SIGTERM, shutting down");
         }
@@ -2287,14 +2280,7 @@ static int event_run(apr_pool_t * _pconf, apr_pool_t * plog, server_rec * s)
 
         if (!child_fatal) {
             /* cleanup pid file on normal shutdown */
-            const char *pidfile = NULL;
-            pidfile = ap_server_root_relative (pconf, ap_pid_fname);
-            if ( pidfile != NULL && unlink(pidfile) == 0)
-                ap_log_error(APLOG_MARK, APLOG_INFO, 0,
-                             ap_server_conf,
-                             "removed PID file %s (pid=%ld)",
-                             pidfile, (long)getpid());
-
+            ap_remove_pid(pconf, ap_pid_fname);
             ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                          "caught " AP_SIG_GRACEFUL_STOP_STRING
                          ", shutting down gracefully");
index 336792b89a78b122fd5ea8774822dff6825eaa24..10284a3ffadc94fdb629fa2fb575ad639ced2438 100644 (file)
@@ -174,14 +174,7 @@ static int mpmt_os2_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
         ap_scoreboard_image->global->running_generation = ap_my_generation;
 
         if (!restart) {
-            const char *pidfile = ap_server_root_relative(pconf, ap_pid_fname);
-
-            if (pidfile != NULL && remove(pidfile) == 0) {
-                ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS,
-                             ap_server_conf, "removed PID file %s (pid=%d)",
-                             pidfile, getpid());
-            }
-
+            ap_remove_pid(pconf, ap_pid_fname);
             ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                          "caught SIGTERM, shutting down");
             return 1;
index 1dec7c41df4da81faf2f19e0f92460ad0c068071..2d6d97c976a99bb7861898069b94362fd37030f9 100644 (file)
@@ -1062,16 +1062,7 @@ static int prefork_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
         ap_reclaim_child_processes(1);          /* Start with SIGTERM */
 
         /* cleanup pid file on normal shutdown */
-        {
-            const char *pidfile = NULL;
-            pidfile = ap_server_root_relative (pconf, ap_pid_fname);
-            if ( pidfile != NULL && unlink(pidfile) == 0)
-                ap_log_error(APLOG_MARK, APLOG_INFO,
-                                0, ap_server_conf,
-                                "removed PID file %s (pid=%ld)",
-                                pidfile, (long)getpid());
-        }
-
+        ap_remove_pid(pconf, ap_pid_fname);
         ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                     "caught SIGTERM, shutting down");
 
@@ -1105,16 +1096,7 @@ static int prefork_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
         ap_relieve_child_processes();
 
         /* cleanup pid file */
-        {
-            const char *pidfile = NULL;
-            pidfile = ap_server_root_relative (pconf, ap_pid_fname);
-            if ( pidfile != NULL && unlink(pidfile) == 0)
-                ap_log_error(APLOG_MARK, APLOG_INFO,
-                                0, ap_server_conf,
-                                "removed PID file %s (pid=%ld)",
-                                pidfile, (long)getpid());
-        }
-
+        ap_remove_pid(pconf, ap_pid_fname);
         ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
            "caught " AP_SIG_GRACEFUL_STOP_STRING ", shutting down gracefully");
 
index 19463991a2106ca070585b9756d100674eb3e03b..a0009e8c8e738a28712cf15e0967dafa82091757 100644 (file)
@@ -1707,13 +1707,7 @@ static int winnt_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
         if (!restart)
         {
             /* Shutting down. Clean up... */
-            const char *pidfile = ap_server_root_relative (pconf, ap_pid_fname);
-
-            if (pidfile != NULL && unlink(pidfile) == 0) {
-                ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS,
-                             ap_server_conf, "removed PID file %s (pid=%ld)",
-                             pidfile, GetCurrentProcessId());
-            }
+            ap_remove_pid(pconf, ap_pid_fname);
             apr_proc_mutex_destroy(start_mutex);
 
             CloseHandle(restart_event);
index 39efd5e0c67f2724e1ea16c6d78092104312a43a..7d373cab5b55bc28e5239bfe46cc9e8d22532752 100644 (file)
@@ -1778,14 +1778,7 @@ static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
 
         if (!child_fatal) {
             /* cleanup pid file on normal shutdown */
-            const char *pidfile = NULL;
-            pidfile = ap_server_root_relative (pconf, ap_pid_fname);
-            if ( pidfile != NULL && unlink(pidfile) == 0)
-                ap_log_error(APLOG_MARK, APLOG_INFO, 0,
-                             ap_server_conf,
-                             "removed PID file %s (pid=%" APR_PID_T_FMT ")",
-                             pidfile, getpid());
-
+            ap_remove_pid(pconf, ap_pid_fname);
             ap_log_error(APLOG_MARK, APLOG_NOTICE, 0,
                          ap_server_conf, "caught SIGTERM, shutting down");
         }
@@ -1805,14 +1798,7 @@ static int worker_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
 
         if (!child_fatal) {
             /* cleanup pid file on normal shutdown */
-            const char *pidfile = NULL;
-            pidfile = ap_server_root_relative (pconf, ap_pid_fname);
-            if ( pidfile != NULL && unlink(pidfile) == 0)
-                ap_log_error(APLOG_MARK, APLOG_INFO, 0,
-                             ap_server_conf,
-                             "removed PID file %s (pid=%" APR_PID_T_FMT ")",
-                             pidfile, getpid());
-
+            ap_remove_pid(pconf, ap_pid_fname);
             ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
                          "caught " AP_SIG_GRACEFUL_STOP_STRING
                          ", shutting down gracefully");