From: Iain Patterson Date: Thu, 17 Feb 2011 00:00:09 +0000 (+0000) Subject: Tidyup TerminateProcess(). X-Git-Tag: v2.8~6 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=47ae0ec9bb0ab33b05469e2780daf1e3f2a3cde1;p=nssm.git 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(). --- diff --git a/messages.mc b/messages.mc index 413eab3..5e5f184 100644 --- a/messages.mc +++ b/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 diff --git a/process.cpp b/process.cpp index 84d2e9a..97b6e38 100644 --- a/process.cpp +++ b/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; } }