Commit f5da9a0a authored by Bill Stoddard's avatar Bill Stoddard
Browse files

Rework the code to handle apache -k shutdown|restart. The fundamental problem

being solved here is determining the best way to discover the Apache
parent process PID (stored in the location specified by the PidFile directive).
This patch attempts to read the config file directly to determine the
pidfile and avoids going through the motions of calling all the module initialization
routines.

This patch will not work if the pidfile directive is in a file pointed to by
an include directive. Not sure is this is a common case or not on Windows.
If it is, it is easy enough to add a bit more code to follow include
directives. An interesting modification would be to detect the presence of a \
-C directive containing a pointer to the pidfile: E.g.,
apache -k restart -C "pidfile d:/mypidfile". Let's keep it simple for now and
see what happens.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84620 13f79535-47bb-0310-9956-ffa450edef68
parent 6f85a86a
Loading
Loading
Loading
Loading
+0 −15
Changes for server/main.c: 0 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -298,10 +298,6 @@ API_EXPORT_NONSTD(int) main(int argc, char *argv[])
    ap_context_t *ptemp; /* Pool for temporary config stuff, reset often */
    ap_context_t *pcommands; /* Pool for -C and -c switches */

#ifdef WIN32
    char *signal = NULL;
#endif

    ap_server_argv0 = process->short_name;
    
    ap_util_uri_init();
@@ -334,11 +330,6 @@ API_EXPORT_NONSTD(int) main(int argc, char *argv[])
	case 'f':
	    confname = ap_optarg;
	    break;
#ifdef WIN32
        case 'k':
	    signal = ap_optarg;
            break;
#endif
	case 'v':
	    printf("Server version: %s\n", ap_get_server_version());
	    printf("Server built:   %s\n", ap_get_server_built());
@@ -377,12 +368,6 @@ API_EXPORT_NONSTD(int) main(int argc, char *argv[])
	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Syntax OK\n");
	destroy_and_exit_process(process, 0);
    }
#ifdef WIN32
    if (signal) {
        ap_signal_parent(pconf, signal, ap_server_root);
        destroy_and_exit_process(process, 0);
    }
#endif
    ap_clear_pool(plog);
    ap_run_open_logs(pconf, plog, ptemp, server_conf);
    ap_post_config_hook(pconf, plog, ptemp, server_conf);
+0 −55
Changes for server/mpm/winnt/mpm_winnt.c: 0 added lines, 55 removed lines.
Original line number Diff line number Diff line
@@ -359,61 +359,6 @@ void ap_start_shutdown(void)
{
    signal_parent(0);
}

void ap_signal_parent(ap_context_t *p, const char* signal, 
                      const char* server_root) 
{
    HANDLE event;
    char prefix[20];
    char *EventName;
    FILE *fp;
    int nread;
    char *fname;
    int end;

    printf("signal = %s\n", signal);

    fname = ap_server_root_relative (p, ap_pid_fname);

    fp = fopen(fname, "r");
    if (!fp) {
	printf("Cannot read apache PID file %s. Error = %d\n", fname, errno);
        return;
    }
    prefix[0] = 'a';
    prefix[1] = 'p';

    nread = fread(prefix+2, 1, sizeof(prefix)-3, fp);
    if (nread == 0) {
	fclose(fp);
	printf("PID file %s was empty\n", fname);
        return;
    }
    fclose(fp);

    /* Terminate the prefix string */
    end = 2 + nread - 1;
    while (end > 0 && (prefix[end] == '\r' || prefix[end] == '\n'))
	end--;
    prefix[end + 1] = '\0';

    /* Build the event name. Should be one of the following...
     * apPID_shutdown
     * apPID_restart
     */
    EventName = ap_pstrcat(p,prefix,"_",signal,NULL);
    printf("event name = %s\n", EventName);
    event = OpenEvent(EVENT_ALL_ACCESS, FALSE, EventName);
    printf("event handle = %d\n", event);
    if (event == NULL) {
	printf("Unable to open event %s.\n", EventName);
        return;
    }
    SetEvent(event);
    ResetEvent(event);
    CloseHandle(event);
    return;
}
/*
 * Initialise the signal names, in the global variables signal_name_prefix, 
 * signal_restart_name and signal_shutdown_name.