- /* Wait for a clean startup. */\r
- if (WaitForSingleObject(process_handle, throttle_delay) == WAIT_TIMEOUT) throttle = 0;\r
+ /*\r
+ Wait for a clean startup before changing the service status to RUNNING\r
+ but be mindful of the fact that we are blocking the service control manager\r
+ so abandon the wait before too much time has elapsed.\r
+ */\r
+ unsigned long delay = throttle_delay;\r
+ if (delay > NSSM_SERVICE_STATUS_DEADLINE) {\r
+ char delay_milliseconds[16];\r
+ _snprintf_s(delay_milliseconds, sizeof(delay_milliseconds), _TRUNCATE, "%lu", delay);\r
+ char deadline_milliseconds[16];\r
+ _snprintf_s(deadline_milliseconds, sizeof(deadline_milliseconds), _TRUNCATE, "%lu", NSSM_SERVICE_STATUS_DEADLINE);\r
+ log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_STARTUP_DELAY_TOO_LONG, service_name, delay_milliseconds, NSSM, deadline_milliseconds, 0);\r
+ delay = NSSM_SERVICE_STATUS_DEADLINE;\r
+ }\r
+ unsigned long deadline = WaitForSingleObject(process_handle, delay);\r