Check we actually have a waitable timer before trying to use it.
Use the correct compiler food to ensure that 256000 milliseconds is
converted to a LARGE_INTEGER correctly.
The registry value %2, used to specify the minimum number of milliseconds which must elapse before service %1 is considered to have started successfully, was not of type REG_DWORD. The default time of %3 milliseconds will be used.
.
The registry value %2, used to specify the minimum number of milliseconds which must elapse before service %1 is considered to have started successfully, was not of type REG_DWORD. The default time of %3 milliseconds will be used.
.
+MessageId = +1
+SymbolicName = NSSM_EVENT_CREATEWAITABLETIMER_FAILED
+Severity = Warning
+Language = English
+Failed to create waitable timer for service %1:
+%2
+Throttled restarts will not be interruptible.
+.
+
\r
/* Used for signalling a resume if the service pauses when throttled. */\r
throttle_timer = CreateWaitableTimer(0, 1, 0);\r
\r
/* Used for signalling a resume if the service pauses when throttled. */\r
throttle_timer = CreateWaitableTimer(0, 1, 0);\r
+ if (! throttle_timer) {\r
+ log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_CREATEWAITABLETIMER_FAILED, service_name, error_string(GetLastError()), 0);\r
+ }\r
\r
monitor_service();\r
}\r
\r
monitor_service();\r
}\r
return NO_ERROR;\r
\r
case SERVICE_CONTROL_CONTINUE:\r
return NO_ERROR;\r
\r
case SERVICE_CONTROL_CONTINUE:\r
+ if (! throttle_timer) return ERROR_CALL_NOT_IMPLEMENTED;\r
throttle = 0;\r
ZeroMemory(&throttle_duetime, sizeof(throttle_duetime));\r
SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0);\r
throttle = 0;\r
ZeroMemory(&throttle_duetime, sizeof(throttle_duetime));\r
SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0);\r
_snprintf(milliseconds, sizeof(milliseconds), "%d", ms);\r
log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service_name, threshold, milliseconds, 0);\r
\r
_snprintf(milliseconds, sizeof(milliseconds), "%d", ms);\r
log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service_name, threshold, milliseconds, 0);\r
\r
- ZeroMemory(&throttle_duetime, sizeof(throttle_duetime));\r
- throttle_duetime.QuadPart = 0 - (ms * 10000);\r
- SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0);\r
+ if (throttle_timer) {\r
+ ZeroMemory(&throttle_duetime, sizeof(throttle_duetime));\r
+ throttle_duetime.QuadPart = 0 - (ms * 10000LL);\r
+ SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0);\r
+ }\r
\r
service_status.dwCurrentState = SERVICE_PAUSED;\r
SetServiceStatus(service_handle, &service_status);\r
\r
\r
service_status.dwCurrentState = SERVICE_PAUSED;\r
SetServiceStatus(service_handle, &service_status);\r
\r
- WaitForSingleObject(throttle_timer, INFINITE);\r
+ if (throttle_timer) WaitForSingleObject(throttle_timer, INFINITE);\r
+ else Sleep(ms);\r