X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=60a8db0b32cf43d9ca3cda01f6381754ad60e029;hb=f1d0155706497569d85c8210e8dd9091278a0e95;hp=4f7ff033dcf80534612788772baca84693cfd0e6;hpb=3405b53f659462281af9f839062b9322d2093277;p=nssm.git diff --git a/service.cpp b/service.cpp index 4f7ff03..60a8db0 100644 --- a/service.cpp +++ b/service.cpp @@ -210,6 +210,9 @@ void WINAPI service_main(unsigned long argc, char **argv) { /* Used for signalling a resume if the service pauses when throttled. */ throttle_timer = CreateWaitableTimer(0, 1, 0); + if (! throttle_timer) { + log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_CREATEWAITABLETIMER_FAILED, service_name, error_string(GetLastError()), 0); + } monitor_service(); } @@ -259,6 +262,7 @@ unsigned long WINAPI service_control_handler(unsigned long control, unsigned lon return NO_ERROR; case SERVICE_CONTROL_CONTINUE: + if (! throttle_timer) return ERROR_CALL_NOT_IMPLEMENTED; throttle = 0; ZeroMemory(&throttle_duetime, sizeof(throttle_duetime)); SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0); @@ -455,12 +459,15 @@ void throttle_restart() { _snprintf(milliseconds, sizeof(milliseconds), "%d", ms); log_event(EVENTLOG_WARNING_TYPE, NSSM_EVENT_THROTTLED, service_name, threshold, milliseconds, 0); - ZeroMemory(&throttle_duetime, sizeof(throttle_duetime)); - throttle_duetime.QuadPart = 0 - (ms * 10000); - SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0); + if (throttle_timer) { + ZeroMemory(&throttle_duetime, sizeof(throttle_duetime)); + throttle_duetime.QuadPart = 0 - (ms * 10000LL); + SetWaitableTimer(throttle_timer, &throttle_duetime, 0, 0, 0, 0); + } service_status.dwCurrentState = SERVICE_PAUSED; SetServiceStatus(service_handle, &service_status); - WaitForSingleObject(throttle_timer, INFINITE); + if (throttle_timer) WaitForSingleObject(throttle_timer, INFINITE); + else Sleep(ms); }