GNUNET_DISK_OPEN_READ
[oweals/gnunet.git] / src / util / os_priority.c
index c017a1e38810b356611163f4ea35176a32a83da0..4e820b8d5cfda1e8efb95d06e35228edb407e762 100644 (file)
@@ -262,7 +262,7 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
  * @param proc process ID
  * @param type status type
  * @param code return code/signal number
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
  */
 int
 GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
@@ -270,9 +270,21 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
 {
 #ifndef MINGW
   int status;
+  int ret;
 
-  if (proc != waitpid (0, &status, WNOHANG))
-    return GNUNET_SYSERR;
+  GNUNET_assert (0 != proc);
+  ret = waitpid (proc, &status, WNOHANG);
+  if (0 == ret) 
+    {
+      *type = GNUNET_OS_PROCESS_RUNNING;
+      *code = 0;
+      return GNUNET_NO;
+    }
+  if (proc != ret)
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
+      return GNUNET_SYSERR;
+    }
   if (WIFEXITED (status))
   {
     *type = GNUNET_OS_PROCESS_EXITED;
@@ -306,6 +318,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
   if (INVALID_HANDLE_VALUE == h)
   {
     SetErrnoFromWinError (GetLastError ());
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess");
     return GNUNET_SYSERR;
   }
 
@@ -314,13 +327,11 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
   {
     *type = GNUNET_OS_PROCESS_RUNNING;
     *code = 0;
+    CloseHandle (h);
+    return GNUNET_NO;
   }
-  else
-  {
-    *type = GNUNET_OS_PROCESS_EXITED;
-    *code = c;
-  }
-
+  *type = GNUNET_OS_PROCESS_EXITED;
+  *code = c;
   CloseHandle (h);
 #endif