From ee52ab253b65c52ff039d8058c66b1a63a656b01 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 13 Nov 2013 15:03:47 +0000 Subject: [PATCH] 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. --- service.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); } -- 2.20.1