-LRN: Better process termination for W32:
authorChristian Grothoff <christian@grothoff.org>
Sat, 23 Jun 2012 22:29:39 +0000 (22:29 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 23 Jun 2012 22:29:39 +0000 (22:29 +0000)
  Avoids spewing warnings about killing processes that are already
dead. Also removes a FIXME.

src/util/os_priority.c

index 3f49290a7be43a3ff82dbf9a2a7a300213102c3b..c9174dee9917155efc363d4ffdccb1d28dad2123 100644 (file)
@@ -455,10 +455,17 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
   case SIGKILL:
   case SIGTERM:
 #if WINDOWS && !defined(__CYGWIN__)
-    if (0 == TerminateProcess (proc->handle, 0))
     {
-      /* FIXME: set 'errno' */
-      return -1;
+      DWORD exitcode;
+      int must_kill = GNUNET_YES;
+      if (0 != GetExitCodeProcess (proc->handle, &exitcode))
+        must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
+      if (GNUNET_YES == must_kill)
+        if (0 == TerminateProcess (proc->handle, 0))
+        {
+          SetErrnoFromWinError (GetLastError ());
+          return -1;
+        }
     }
     return 0;
 #else