From: Iain Patterson Date: Wed, 7 May 2014 07:33:35 +0000 (+0100) Subject: Restart in response to PBT_APMRESUMEAUTOMATIC event. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=17868b50b4da483cd0f8c343ede264799177cdbf;p=nssm.git Restart in response to PBT_APMRESUMEAUTOMATIC event. --- diff --git a/service.cpp b/service.cpp index 61d4b84..3d3acb9 100644 --- a/service.cpp +++ b/service.cpp @@ -1362,7 +1362,7 @@ void WINAPI service_main(unsigned long argc, TCHAR **argv) { /* Initialise status */ ZeroMemory(&service->status, sizeof(service->status)); service->status.dwServiceType = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS; - service->status.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE; + service->status.dwControlsAccepted = SERVICE_ACCEPT_POWEREVENT | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE; service->status.dwWin32ExitCode = NO_ERROR; service->status.dwServiceSpecificExitCode = 0; service->status.dwCheckPoint = 0; @@ -1460,6 +1460,7 @@ TCHAR *service_control_text(unsigned long control) { case SERVICE_CONTROL_CONTINUE: return _T("CONTINUE"); case SERVICE_CONTROL_INTERROGATE: return _T("INTERROGATE"); case NSSM_SERVICE_CONTROL_ROTATE: return _T("ROTATE"); + case SERVICE_CONTROL_POWEREVENT: return _T("POWEREVENT"); default: return 0; } } @@ -1567,6 +1568,15 @@ unsigned long WINAPI service_control_handler(unsigned long control, unsigned lon if (service->rotate_stdout_online == NSSM_ROTATE_ONLINE) service->rotate_stdout_online = NSSM_ROTATE_ONLINE_ASAP; if (service->rotate_stderr_online == NSSM_ROTATE_ONLINE) service->rotate_stderr_online = NSSM_ROTATE_ONLINE_ASAP; return NO_ERROR; + + case SERVICE_CONTROL_POWEREVENT: + if (event != PBT_APMRESUMEAUTOMATIC) { + log_service_control(service->name, control, false); + return NO_ERROR; + } + log_service_control(service->name, control, true); + end_service((void *) service, false); + return NO_ERROR; } /* Unknown control */