X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=0c2368e7d37d29932f0586e4e780a59348eafd34;hb=5e7f7c21e254ba722d5d0d08c154792b82cf3f1d;hp=766031ee9e9a3e186b42b07a014d32bdec996323;hpb=f2ec1c0c55a6b3e8ca02b3d66b78c87fe0ac1f47;p=nssm.git diff --git a/service.cpp b/service.cpp index 766031e..0c2368e 100644 --- a/service.cpp +++ b/service.cpp @@ -453,8 +453,18 @@ void CALLBACK end_service(void *arg, unsigned char why) { /* Check exit code */ unsigned long exitcode = 0; + char code[16]; GetExitCodeProcess(process_handle, &exitcode); + /* + Log that the service ended BEFORE logging about killing the process + tree. See below for the possible values of the why argument. + */ + if (! why) { + _snprintf(code, sizeof(code), "%d", exitcode); + log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_ENDED_SERVICE, exe, service_name, code, 0); + } + /* Clean up. */ kill_process_tree(service_name, pid, exitcode, pid); @@ -466,10 +476,6 @@ void CALLBACK end_service(void *arg, unsigned char why) { */ if (why) return; - char code[16]; - _snprintf(code, sizeof(code), "%d", exitcode); - log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_ENDED_SERVICE, exe, service_name, code, 0); - /* What action should we take? */ int action = NSSM_EXIT_RESTART; unsigned char action_string[ACTION_LEN];