new version
[rrq/overlay-boot.git] / src / reaper.c
index f1c2f9aea09e3c2a11f6e49965798cd3614c7ab5..9da212494dafadd9022e3cfc288b453aef2a39fc 100644 (file)
@@ -1,19 +1,21 @@
-#include <errno.h>
+/**
+ * This program waits for child process and "reaps" them, i.e. read
+ * off their status so that they can terminate. The program exits when
+ * it runs out of children.
+ */
 #include <signal.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/wait.h>
-#include <sys/types.h>
 
 int main(void) {
-       sigset_t set;
-       siginfo_t status;
+    sigset_t set;
+    siginfo_t status;
 
-       if (getpid()!=1)
-               return 1;
-       sigfillset(&set);
-       sigprocmask(SIG_BLOCK,&set,NULL);
-       memset(&status,0,sizeof status);
-       while (-ECHILD!=waitid(P_ALL,0,&status,WEXITED));
-       return 1;
+    sigfillset(&set);
+    sigprocmask(SIG_BLOCK,&set,NULL);
+
+    do {
+       memset( &status, 0, sizeof( status ) );
+    } while ( waitid( P_ALL, 0, &status, WEXITED ) == 0 );
+    return 0;
 }