Browse Source

Tidyup TerminateProcess().

TerminateProcess() will fail if the process already died for some
reason.  Don't log an error in this case.

Log a more interesting message when recursing into kill_process_tree().
Iain Patterson 11 years ago
parent
commit
47ae0ec9bb
2 changed files with 4 additions and 2 deletions
  1. 1 1
      messages.mc
  2. 3 1
      process.cpp

+ 1 - 1
messages.mc

@@ -177,7 +177,7 @@ MessageId = +1
 SymbolicName = NSSM_EVENT_KILLING
 Severity = Informational
 Language = English
-kill_process_tree %1 %2 %3
+Killing process tree of process %2 for service %1 with exit code %3
 .
 
 MessageId = +1

+ 3 - 1
process.cpp

@@ -149,7 +149,9 @@ void kill_process_tree(char *service_name, unsigned long pid, unsigned long exit
   _snprintf(ppid_string, sizeof(ppid_string), "%d", ppid);
   log_event(EVENTLOG_INFORMATION_TYPE, NSSM_EVENT_KILL_PROCESS_TREE, pid_string, ppid_string, service_name, 0);
   if (! kill_process(service_name, process_handle, pid, exitcode)) {
-    log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_TERMINATEPROCESS_FAILED, pid_string, service_name, error_string(GetLastError()), 0);
+    /* Maybe it already died. */
+    unsigned long ret;
+    if (! GetExitCodeProcess(process_handle, &ret)) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_TERMINATEPROCESS_FAILED, pid_string, service_name, error_string(GetLastError()), 0);
     return;
   }
 }