Calculate service stop wait hint correctly.
authorIain Patterson <me@iain.cx>
Wed, 13 Nov 2013 15:03:47 +0000 (15:03 +0000)
committerIain Patterson <me@iain.cx>
Fri, 15 Nov 2013 16:02:54 +0000 (16:02 +0000)
The wait hint when changing the service status to stopped failed to take
into account the grace period after sending a Control-C event.  It also
failed to consider the case where one or more stop methods were
disabled.

service.cpp

index d8dd1aa..596aa7e 100644 (file)
@@ -445,7 +445,10 @@ int stop_service(unsigned long exitcode, bool graceful, bool default_action) {
   /* Signal we are stopping */\r
   if (graceful) {\r
     service_status.dwCurrentState = SERVICE_STOP_PENDING;\r
-    service_status.dwWaitHint = NSSM_KILL_WINDOW_GRACE_PERIOD + NSSM_KILL_THREADS_GRACE_PERIOD + NSSM_WAITHINT_MARGIN;\r
+    service_status.dwWaitHint = NSSM_WAITHINT_MARGIN;\r
+    if (stop_method & NSSM_STOP_METHOD_CONSOLE && imports.AttachConsole) service_status.dwWaitHint += NSSM_KILL_CONSOLE_GRACE_PERIOD;\r
+    if (stop_method & NSSM_STOP_METHOD_WINDOW) service_status.dwWaitHint += NSSM_KILL_WINDOW_GRACE_PERIOD;\r
+    if (stop_method & NSSM_STOP_METHOD_THREADS) service_status.dwWaitHint += NSSM_KILL_THREADS_GRACE_PERIOD;\r
     SetServiceStatus(service_handle, &service_status);\r
   }\r
 \r