From: Jeff Trawick Date: Mon, 28 Mar 2011 13:35:08 +0000 (+0000) Subject: consolidate logic to remove the pidfile in a new API, X-Git-Tag: 2.3.12~166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7be2d26631bb0c7bb3114e8985572cea6f978d5e;p=thirdparty%2Fapache%2Fhttpd.git consolidate logic to remove the pidfile in a new API, 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 --- diff --git a/CHANGES b/CHANGES index be2eee6e2f2..e0ee0ded53b 100644 --- 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 diff --git a/include/http_log.h b/include/http_log.h index d635ab1cf25..f2aa4c7fd7d 100644 --- a/include/http_log.h +++ b/include/http_log.h @@ -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) */ diff --git a/server/log.c b/server/log.c index 4f7bf081b6a..50d9cbcb3ed 100644 --- a/server/log.c +++ b/server/log.c @@ -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; diff --git a/server/mpm/event/event.c b/server/mpm/event/event.c index 4b0cf39e619..81c2ba86953 100644 --- a/server/mpm/event/event.c +++ b/server/mpm/event/event.c @@ -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"); diff --git a/server/mpm/mpmt_os2/mpmt_os2.c b/server/mpm/mpmt_os2/mpmt_os2.c index 336792b89a7..10284a3ffad 100644 --- a/server/mpm/mpmt_os2/mpmt_os2.c +++ b/server/mpm/mpmt_os2/mpmt_os2.c @@ -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; diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 1dec7c41df4..2d6d97c976a 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -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"); diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 19463991a21..a0009e8c8e7 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -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); diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 39efd5e0c67..7d373cab5b5 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -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");