From: Iain Patterson Date: Wed, 13 Nov 2013 15:03:47 +0000 (+0000) Subject: Calculate service stop wait hint correctly. X-Git-Tag: v2.18~10 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=ee52ab253b65c52ff039d8058c66b1a63a656b01;hp=64eea0aef7d23dc4cfdaa7d979473c629f41ab85;p=nssm.git Calculate service stop wait hint correctly. 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. --- diff --git a/service.cpp b/service.cpp index d8dd1aa..596aa7e 100644 --- a/service.cpp +++ b/service.cpp @@ -445,7 +445,10 @@ int stop_service(unsigned long exitcode, bool graceful, bool default_action) { /* Signal we are stopping */ if (graceful) { service_status.dwCurrentState = SERVICE_STOP_PENDING; - service_status.dwWaitHint = NSSM_KILL_WINDOW_GRACE_PERIOD + NSSM_KILL_THREADS_GRACE_PERIOD + NSSM_WAITHINT_MARGIN; + service_status.dwWaitHint = NSSM_WAITHINT_MARGIN; + if (stop_method & NSSM_STOP_METHOD_CONSOLE && imports.AttachConsole) service_status.dwWaitHint += NSSM_KILL_CONSOLE_GRACE_PERIOD; + if (stop_method & NSSM_STOP_METHOD_WINDOW) service_status.dwWaitHint += NSSM_KILL_WINDOW_GRACE_PERIOD; + if (stop_method & NSSM_STOP_METHOD_THREADS) service_status.dwWaitHint += NSSM_KILL_THREADS_GRACE_PERIOD; SetServiceStatus(service_handle, &service_status); }