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

[tyndur-devel] [PATCH 6/6] libc: POSIX: waitpid mit WNOHANG



+ libc: POSIX: WNOHANG fuer wait implementiert
+ libc: Warnung bei waitpid mit pid = -1 ausgeben (ist nicht
  implementiert)

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/include/sys/wait.h |    2 ++
 src/modules/lib/posix/wait.c   |   10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/modules/include/sys/wait.h b/src/modules/include/sys/wait.h
index 2a8a914..7831650 100644
--- a/src/modules/include/sys/wait.h
+++ b/src/modules/include/sys/wait.h
@@ -35,6 +35,8 @@
 
 #define WEXITSTATUS(status) (status)
 
+#define WNOHANG 1
+
 
 pid_t wait(int* status);
 pid_t waitpid(pid_t pid, int* status, int options);
diff --git a/src/modules/lib/posix/wait.c b/src/modules/lib/posix/wait.c
index 13521a0..be562eb 100644
--- a/src/modules/lib/posix/wait.c
+++ b/src/modules/lib/posix/wait.c
@@ -33,6 +33,7 @@
 #include <sys/types.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <stdio.h>
 
 struct wait_child {
     pid_t pid;
@@ -159,8 +160,12 @@ pid_t waitpid(pid_t pid, int* status, int options)
         }
         
         // Warten bis der Prozess terminiert
-        while (wait_child->running && (get_parent_pid(pid) != 0)) {
-            yield();
+        if ((options & WNOHANG) == 0) {
+            while (wait_child->running && (get_parent_pid(pid) != 0)) {
+                yield();
+            }
+        } else if (wait_child->running) {
+            return 0;
         }
         
         if (status != NULL) {
@@ -170,6 +175,7 @@ pid_t waitpid(pid_t pid, int* status, int options)
         return pid;
     } else {
         // Irgend ein Prozess (FIXME)
+        printf("waitpid(-1)\n");
         errno = ECHILD;
         return -1;
     }
-- 
1.6.0.2