You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ko...@apache.org on 2017/07/11 21:39:36 UTC

svn commit: r1801659 - /httpd/httpd/trunk/server/mpm/winnt/service.c

Author: kotkov
Date: Tue Jul 11 21:39:35 2017
New Revision: 1801659

URL: http://svn.apache.org/viewvc?rev=1801659&view=rev
Log:
mpm_winnt: Advertise support for preshutdown notifications in the service,
and perform shutdown in respond to SERVICE_CONTROL_PRESHUTDOWN.

The pure shutdown notification leaves a small amount of time for the service
to finish (and the allowed amount of time has been shrinking with every new
version of Windows), and handling only it increases the chance of the process
being killed by SCM, instead of gracefully shutting down.  Handling the
preshutdown control code extends this period, and increases the chances of
finishing everything properly when the machine is rebooted or shut down.

(See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683241)

Please note that although the preshutdown notifications are available only
starting from Windows Vista, the code is compatible with the previous versions
of Windows, since the SCM ignores unknown SERVICE_ACCEPT codes, and will
still send an ordinary SERVICE_CONTROL_SHUTDOWN under old Windows
versions.

Modified:
    httpd/httpd/trunk/server/mpm/winnt/service.c

Modified: httpd/httpd/trunk/server/mpm/winnt/service.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/winnt/service.c?rev=1801659&r1=1801658&r2=1801659&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/winnt/service.c (original)
+++ httpd/httpd/trunk/server/mpm/winnt/service.c Tue Jul 11 21:39:35 2017
@@ -231,7 +231,8 @@ static int ReportStatusToSCMgr(int curre
             ctx->ssStatus.dwWaitHint = 0;
             ctx->ssStatus.dwCheckPoint = 0;
             ctx->ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP
-                                             | SERVICE_ACCEPT_SHUTDOWN;
+                                             | SERVICE_ACCEPT_SHUTDOWN
+                                             | SERVICE_ACCEPT_PRESHUTDOWN;
         }
         else if (currentState == SERVICE_STOPPED) {
             ctx->ssStatus.dwWaitHint = 0;
@@ -345,7 +346,8 @@ static DWORD WINAPI service_nt_ctrl(DWOR
 
     /* SHUTDOWN is offered before STOP, accept the first opportunity */
     if ((dwCtrlCode == SERVICE_CONTROL_STOP)
-         || (dwCtrlCode == SERVICE_CONTROL_SHUTDOWN))
+         || (dwCtrlCode == SERVICE_CONTROL_SHUTDOWN)
+         || (dwCtrlCode == SERVICE_CONTROL_PRESHUTDOWN))
     {
         ap_signal_parent(SIGNAL_PARENT_SHUTDOWN);
         ReportStatusToSCMgr(SERVICE_STOP_PENDING, 30000, ctx);