Tidyup TerminateProcess().
authorIain Patterson <me@iain.cx>
Thu, 17 Feb 2011 00:00:09 +0000 (00:00 +0000)
committerIain Patterson <me@iain.cx>
Thu, 17 Feb 2011 00:00:09 +0000 (00:00 +0000)
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().

messages.mc
process.cpp

index 413eab3..5e5f184 100644 (file)
@@ -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
index 84d2e9a..97b6e38 100644 (file)
@@ -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;
   }
 }