gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8549 - in gnunet/src: arm include util


From: gnunet
Subject: [GNUnet-SVN] r8549 - in gnunet/src: arm include util
Date: Thu, 11 Jun 2009 07:39:33 -0600

Author: durner
Date: 2009-06-11 07:39:32 -0600 (Thu, 11 Jun 2009)
New Revision: 8549

Modified:
   gnunet/src/arm/gnunet-service-arm.c
   gnunet/src/include/gnunet_os_lib.h
   gnunet/src/util/os_priority.c
Log:
poll PIDs for status information

Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2009-06-11 06:10:51 UTC (rev 8548)
+++ gnunet/src/arm/gnunet-service-arm.c 2009-06-11 13:39:32 UTC (rev 8549)
@@ -549,7 +549,6 @@
 {
   struct ServiceList *pos;
   pid_t pid;
-  int status;
   const char *statstr;
   int statcode;
   struct stat sbuf;
@@ -562,7 +561,7 @@
           running = pos->next;
           if (0 != PLIBC_KILL (pos->pid, SIGTERM))
             GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-          if (pos->pid != waitpid (pos->pid, NULL, 0))
+          if (GNUNET_OK != GNUNET_OS_process_wait(pos->pid))
             GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
           free_entry (pos);
         }
@@ -575,25 +574,28 @@
                                 MAINT_FREQUENCY, &maint, cfg);
 
   /* check for services that died (WAITPID) */
-  while (0 < (pid = waitpid (0, &status, WNOHANG)))
+  for (pos = running; pos != NULL; pos = pos->next)
     {
-      if (WIFSTOPPED (status) || WIFCONTINUED (status))
+      enum GNUNET_OS_ProcessStatusType statusType;
+      unsigned long statusCode;
+
+      if (GNUNET_OS_process_status(pos->pid, &statusType, &statusCode) != 
GNUNET_OK)
+      {
+        GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, 
"GNUNET_OS_process_status");
         continue;
-      pos = find_pid (pid);
-      if (pos == NULL)
+      }
+
+      if (statusType == GNUNET_OS_PROCESS_STOPPED || statusType == 
GNUNET_OS_PROCESS_RUNNING)
+        continue;
+      else if (statusType == GNUNET_OS_PROCESS_EXITED)
         {
-          /* we killed the service */
-          continue;
-        }
-      if (WIFEXITED (status))
-        {
           statstr = _( /* process termination method */ "exit");
-          statcode = WEXITSTATUS (status);
+          statcode = statusCode;
         }
-      else if (WTERMSIG (status))
+      else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
         {
           statstr = _( /* process termination method */ "signal");
-          statcode = WTERMSIG (status);
+          statcode = statusCode;
         }
       else
         {

Modified: gnunet/src/include/gnunet_os_lib.h
===================================================================
--- gnunet/src/include/gnunet_os_lib.h  2009-06-11 06:10:51 UTC (rev 8548)
+++ gnunet/src/include/gnunet_os_lib.h  2009-06-11 13:39:32 UTC (rev 8549)
@@ -60,6 +60,19 @@
 
 
 /**
+ * Process status types
+ */
+enum GNUNET_OS_ProcessStatusType
+{
+  GNUNET_OS_PROCESS_UNKNOWN,
+  GNUNET_OS_PROCESS_RUNNING,
+  GNUNET_OS_PROCESS_STOPPED,
+  GNUNET_OS_PROCESS_EXITED,
+  GNUNET_OS_PROCESS_SIGNALED
+};
+
+
+/**
  * Get the path to a specific GNUnet installation directory or, with
  * GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation
  * directory.
@@ -145,6 +158,23 @@
  */
 pid_t GNUNET_OS_start_process_v (const char *filename, char *const argv[]);
 
+/**
+ * Retrieve the status of a process
+ * @param proc process ID
+ * @param type status type
+ * @param code return code/signal number
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+int GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType 
*type,
+    unsigned long *code);
+
+/**
+ * Wait for a process
+ * @param proc process ID to wait for
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+int GNUNET_OS_process_wait (pid_t proc);
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c       2009-06-11 06:10:51 UTC (rev 8548)
+++ gnunet/src/util/os_priority.c       2009-06-11 13:39:32 UTC (rev 8549)
@@ -257,9 +257,114 @@
 #endif
 }
 
+/**
+ * Retrieve the status of a process
+ * @param proc process ID
+ * @param type status type
+ * @param code return code/signal number
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
+    unsigned long *code)
+{
+#ifndef MINGW
+  int status;
 
+  if (proc != waitpid (0, &status, WNOHANG))
+    return GNUNET_SYSERR;
+  if (WIFEXITED (status))
+  {
+    *type = GNUNET_OS_PROCESS_EXITED;
+    *code = WEXITSTATUS (status);
+  }
+  else if (WIFSIGNALED (status))
+  {
+    *type = GNUNET_OS_PROCESS_SIGNALED;
+    *code = WTERMSIG (status);
+  }
+  else if (WIFSTOPPED (status))
+  {
+    *type = GNUNET_OS_PROCESS_SIGNALED;
+    *code = WSTOPSIG (status);
+  }
+  else if (WIFCONTINUED (status))
+  {
+    *type = GNUNET_OS_PROCESS_RUNNING;
+    *code = 0;
+  }
+  else
+  {
+    *type = GNUNET_OS_PROCESS_UNKNOWN;
+    *code = 0;
+  }
+#else
+  HANDLE h;
+  DWORD c;
 
+  h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
+  if (INVALID_HANDLE_VALUE == h)
+  {
+    SetErrnoFromWinError (GetLastError ());
+    return GNUNET_SYSERR;
+  }
 
+  c = GetExitCodeProcess (proc, &c);
+  if (STILL_ACTIVE == c)
+  {
+    *type = GNUNET_OS_PROCESS_RUNNING;
+    *code = 0;
+  }
+  else
+  {
+    *type = GNUNET_OS_PROCESS_EXITED;
+    *code = c;
+  }
 
+  CloseHandle (h);
+#endif
 
+  return GNUNET_OK;
+}
+
+/**
+ * Wait for a process
+ * @param proc process ID to wait for
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+int
+GNUNET_OS_process_wait (pid_t proc)
+{
+#ifndef MINGW
+  if (proc != waitpid (proc, NULL, 0))
+    return GNUNET_SYSERR;
+
+  return GNUNET_OK;
+#else
+  HANDLE h;
+  DWORD c;
+  int ret;
+
+  h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
+  if (INVALID_HANDLE_VALUE == h)
+  {
+    SetErrnoFromWinError (GetLastError ());
+    return GNUNET_SYSERR;
+  }
+
+  if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
+  {
+    SetErrnoFromWinError (GetLastError ());
+    ret = GNUNET_SYSERR;
+  }
+  else
+    ret = GNUNET_OK;
+
+  CloseHandle (h);
+
+  return ret;
+#endif
+}
+
+
 /* end of os_priority.c */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]