NSSM 2.14.
[nssm.git] / service.cpp
index 766031e..0c2368e 100644 (file)
@@ -453,8 +453,18 @@ void CALLBACK end_service(void *arg, unsigned char why) {
 \r
   /* Check exit code */\r
   unsigned long exitcode = 0;\r
+  char code[16];\r
   GetExitCodeProcess(process_handle, &exitcode);\r
 \r
+  /*\r
+    Log that the service ended BEFORE logging about killing the process\r
+    tree.  See below for the possible values of the why argument.\r
+  */\r
+  if (! why) {\r
+    _snprintf(code, sizeof(code), "%d", exitcode);\r
+    log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_ENDED_SERVICE, exe, service_name, code, 0);\r
+  }\r
+\r
   /* Clean up. */\r
   kill_process_tree(service_name, pid, exitcode, pid);\r
 \r
@@ -466,10 +476,6 @@ void CALLBACK end_service(void *arg, unsigned char why) {
   */\r
   if (why) return;\r
 \r
-  char code[16];\r
-  _snprintf(code, sizeof(code), "%d", exitcode);\r
-  log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_ENDED_SERVICE, exe, service_name, code, 0);\r
-\r
   /* What action should we take? */\r
   int action = NSSM_EXIT_RESTART;\r
   unsigned char action_string[ACTION_LEN];\r