From: Bill Stoddard Date: Wed, 17 Oct 2001 15:51:22 +0000 (+0000) Subject: Win32: Deprecate ap_start_shutdown/ap_start_restart in favor of ap_signal_parent... X-Git-Tag: 2.0.27~104 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5084ba0359279d16c9c71b045a35ee17466b102;p=apache 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 --- diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index c8a4c97c19..86c748abb6 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -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, diff --git a/server/mpm/winnt/mpm_winnt.h b/server/mpm/winnt/mpm_winnt.h index 41929e308f..4bb6014686 100644 --- a/server/mpm/winnt/mpm_winnt.h +++ b/server/mpm/winnt/mpm_winnt.h @@ -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. diff --git a/server/mpm/winnt/service.c b/server/mpm/winnt/service.c index 71605972e2..ee9559a041 100644 --- a/server/mpm/winnt/service.c +++ b/server/mpm/winnt/service.c @@ -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); } } }