Commit 955609d1 authored by Bill Stoddard's avatar Bill Stoddard
Browse files

Win32: Deprecate ap_start_shutdown/ap_start_restart in favor of ap_signal_parent(enum).

This simplifies the code a bit for some more MPM cleanup work forthcoming.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@91529 13f79535-47bb-0310-9956-ffa450edef68
parent 357d56cd
Loading
Loading
Loading
Loading
+26 −32
Original line number Diff line number Diff line
@@ -292,26 +292,39 @@ void setup_signal_names(char *prefix)
	"%s_restart", signal_name_prefix);    
}

void signal_parent(int type)
static int volatile is_graceful = 0;
AP_DECLARE(int) ap_graceful_stop_signalled(void)
{
    return is_graceful;
}

AP_DECLARE(void) ap_signal_parent(ap_signal_parent_e type)
{
    HANDLE e;
    char *signal_name;
    
    /* after updating the shutdown_pending or restart flags, we need
     * to wake up the parent process so it can see the changes. The
     * parent will normally be waiting for either a child process
     * to die, or for a signal on the "spache-signal" event. So set the
     * "apache-signal" event here.
     */
    if (one_process) {
	return;
    }

    switch(type) {
    case 0: signal_name = signal_shutdown_name; break;
    case 1: signal_name = signal_restart_name; break;
    default: return;
       case SIGNAL_PARENT_SHUTDOWN: 
       {
           signal_name = signal_shutdown_name; 
           break;
       }
       /* This MPM supports only graceful restarts right now */
       case SIGNAL_PARENT_RESTART: 
       case SIGNAL_PARENT_RESTART_GRACEFUL:
       {
           signal_name = signal_restart_name;     
           is_graceful = 1;
           break;
       }
       default: 
           return;
    }

    e = OpenEvent(EVENT_ALL_ACCESS, FALSE, signal_name);
    if (!e) {
	/* Um, problem, can't signal the parent, which means we can't
@@ -331,25 +344,6 @@ void signal_parent(int type)
    CloseHandle(e);
}

static int volatile is_graceful = 0;

AP_DECLARE(int) ap_graceful_stop_signalled(void)
{
    return is_graceful;
}

AP_DECLARE(void) ap_start_shutdown(void)
{
    signal_parent(0);
}

AP_DECLARE(void) ap_start_restart(int gracefully)
{
    is_graceful = gracefully;
    signal_parent(1);
}


/*
 * find_ready_listener()
 * Only used by Win9* and should go away when the win9*_accept() function is 
@@ -409,7 +403,7 @@ static int get_listeners_from_parent(server_rec *s)
                      &BytesRead, (LPOVERLAPPED) NULL)) {
            ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), server_conf,
                         "setup_inherited_listeners: Unable to read socket data from parent");
            signal_parent(0);	/* tell parent to die */
            ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
            exit(1);
        }
        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, APR_SUCCESS, server_conf,
@@ -419,7 +413,7 @@ static int get_listeners_from_parent(server_rec *s)
        if (nsd == INVALID_SOCKET) {
            ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_netos_error(), server_conf,
                         "Child %d: setup_inherited_listeners(), WSASocket failed to open the inherited socket.", my_pid);
            signal_parent(0);	/* tell parent to die */
            ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
            exit(1);
        }
        apr_os_sock_put(&lr->sd, &nsd, pconf);
@@ -992,7 +986,7 @@ static void child_main()
    if (status != APR_SUCCESS) {
	ap_log_error(APLOG_MARK,APLOG_ERR, status, server_conf,
                     "Child %d: Failed to acquire the start_mutex. Process will exit.", my_pid);
        signal_parent(0);	/* tell parent to die */
        ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
	exit(0);
    }
    ap_log_error(APLOG_MARK,APLOG_INFO, APR_SUCCESS, server_conf, 
+6 −4
Original line number Diff line number Diff line
@@ -117,12 +117,14 @@ void mpm_start_child_console_handler(void);
extern OSVERSIONINFO osver;
extern void clean_child_exit(int);

AP_DECLARE(void) ap_start_shutdown(void);
AP_DECLARE(void) ap_start_restart(int gracefully);

void setup_signal_names(char *prefix);
void signal_parent(int type);

typedef enum {
    SIGNAL_PARENT_SHUTDOWN,
    SIGNAL_PARENT_RESTART,
    SIGNAL_PARENT_RESTART_GRACEFUL
} ap_signal_parent_e;
AP_DECLARE(void) ap_signal_parent(ap_signal_parent_e type);

/* This code is stolen from the apr_private.h and misc/win32/misc.c
 * Please see those sources for detailed documentation.
+8 −8
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ static LRESULT CALLBACK monitor_service_9x_proc(HWND hWnd, UINT msg,
    if ((msg == WM_ENDSESSION) 
            && (die_on_logoff || (lParam != ENDSESSION_LOGOFF)))
    {
        signal_parent(0);
        ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
	if (wParam)
            /* Don't leave this message until we are dead! */
	    WaitForSingleObject(globdat.mpm_thread, 30000);
@@ -274,7 +274,7 @@ static BOOL CALLBACK console_control_handler(DWORD ctrl_type)
    {
        case CTRL_BREAK_EVENT:
            fprintf(stderr, "Apache server restarting...\n");
            signal_parent(1);
            ap_signal_parent(SIGNAL_PARENT_RESTART);
            return TRUE;
        case CTRL_C_EVENT:
            fprintf(stderr, "Apache server interrupted...\n");
@@ -282,7 +282,7 @@ static BOOL CALLBACK console_control_handler(DWORD ctrl_type)
             * Tell the system we have dealt with the signal
             * without waiting for Apache to terminate.
             */
            signal_parent(0);
            ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
            return TRUE;

        case CTRL_CLOSE_EVENT:
@@ -295,7 +295,7 @@ static BOOL CALLBACK console_control_handler(DWORD ctrl_type)
             * THESE EVENTS WILL NOT OCCUR UNDER WIN9x!
             */
            fprintf(stderr, "Apache server shutdown initiated...\n");
            signal_parent(0);
            ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
            Sleep(30000);
            return TRUE;
    }
@@ -484,14 +484,14 @@ static VOID WINAPI service_nt_ctrl(DWORD dwCtrlCode)
{
    if (dwCtrlCode == SERVICE_CONTROL_STOP)
    {
        ap_start_shutdown();
        ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
        globdat.ssStatus.dwCurrentState = SERVICE_STOP_PENDING;
        ReportStatusToSCMgr(SERVICE_STOP_PENDING, NO_ERROR, 3000);
        return;
    }
    if (dwCtrlCode == SERVICE_APACHE_RESTART)
    {
        ap_start_restart(1);
        ap_signal_parent(SIGNAL_PARENT_RESTART);
        globdat.ssStatus.dwCurrentState = SERVICE_START_PENDING;
        ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000);
        return;
@@ -1337,7 +1337,7 @@ void mpm_signal_service(apr_pool_t *ptemp, int signal)
        if (!signal) 
        {
            int ticks = 60;
            ap_start_shutdown();
            ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
            while (--ticks)
            {
                if (!IsWindow(hwnd)) {
@@ -1360,7 +1360,7 @@ void mpm_signal_service(apr_pool_t *ptemp, int signal)
            }
            else {
                success = TRUE;
                ap_start_restart(1);
                ap_signal_parent(SIGNAL_PARENT_RESTART);
            }
        }
    }