Don't try to kill a process which didn't start.
authorIain Patterson <me@iain.cx>
Tue, 26 Nov 2013 12:43:06 +0000 (12:43 +0000)
committerIain Patterson <me@iain.cx>
Tue, 26 Nov 2013 20:38:05 +0000 (20:38 +0000)
If CreateProcess() failed there's no sense trying to call
GetExitCodeProcess() or kill_process_tree().

service.cpp

index 294497a..ea4b633 100644 (file)
@@ -551,12 +551,14 @@ void CALLBACK end_service(void *arg, unsigned char why) {
   /* Check exit code */\r
   unsigned long exitcode = 0;\r
   TCHAR code[16];\r
-  GetExitCodeProcess(service->process_handle, &exitcode);\r
-  if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);\r
-  CloseHandle(service->process_handle);\r
+  if (service->process_handle) {\r
+    GetExitCodeProcess(service->process_handle, &exitcode);\r
+    if (exitcode == STILL_ACTIVE || get_process_exit_time(service->process_handle, &service->exit_time)) GetSystemTimeAsFileTime(&service->exit_time);\r
+    CloseHandle(service->process_handle);\r
+  }\r
+  else GetSystemTimeAsFileTime(&service->exit_time);\r
 \r
   service->process_handle = 0;\r
-  service->pid = 0;\r
 \r
   /*\r
     Log that the service ended BEFORE logging about killing the process\r
@@ -569,7 +571,8 @@ void CALLBACK end_service(void *arg, unsigned char why) {
 \r
   /* Clean up. */\r
   if (exitcode == STILL_ACTIVE) exitcode = 0;\r
-  kill_process_tree(service, service->pid, exitcode, service->pid);\r
+  if (service->pid) kill_process_tree(service, service->pid, exitcode, service->pid);\r
+  service->pid = 0;\r
 \r
   /*\r
     The why argument is true if our wait timed out or false otherwise.\r