Commit 04bdfcdc authored by Jeff Trawick's avatar Jeff Trawick
Browse files

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
parent c229d0f1
Loading
Loading
Loading
Loading
+2 −0
Changes for CHANGES: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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
+9 −2
Changes for include/http_log.h: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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)
 */
+19 −0
Changes for server/log.c: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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;
+2 −16
Changes for server/mpm/event/event.c: 2 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -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");
+1 −8
Changes for server/mpm/mpmt_os2/mpmt_os2.c: 1 added line, 8 removed lines.
Original line number Diff line number Diff line
@@ -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;
Loading