[hackers] [sinit] Ensure children are reaped periodically || sin

From: <git_AT_suckless.org>
Date: Sun, 18 Mar 2018 14:46:44 +0100 (CET)

commit 170d599d58efee6c9be675a85c6e435d68e8a2de
Author: sin <sin_AT_2f30.org>
AuthorDate: Sun Mar 18 13:35:38 2018 +0000
Commit: sin <sin_AT_2f30.org>
CommitDate: Sun Mar 18 13:43:25 2018 +0000

    Ensure children are reaped periodically
    
    There is a pathological case where a parent receives SIGCHLD after its
    child dies but does not reap it. After the parent dies, the child is
    reparented to init but SIGCHLD is not redelivered.
    
    To fix this, periodically check if there are zombies pending to be
    reaped.

diff --git a/sinit.c b/sinit.c
index 93f9925..7166710 100644
--- a/sinit.c
+++ b/sinit.c
_AT_@ -7,7 +7,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#define LEN(x) (sizeof (x) / sizeof *(x))
+#define LEN(x) (sizeof (x) / sizeof *(x))
+#define TIMEO 30
 
 static void sigpoweroff(void);
 static void sigreap(void);
_AT_@ -20,6 +21,7 @@ static struct {
 } sigmap[] = {
         { SIGUSR1, sigpoweroff },
         { SIGCHLD, sigreap },
+ { SIGALRM, sigreap },
         { SIGINT, sigreboot },
 };
 
_AT_@ -40,6 +42,7 @@ main(void)
         sigprocmask(SIG_BLOCK, &set, NULL);
         spawn(rcinitcmd);
         while (1) {
+ alarm(TIMEO);
                 sigwait(&set, &sig);
                 for (i = 0; i < LEN(sigmap); i++) {
                         if (sigmap[i].sig == sig) {
_AT_@ -63,6 +66,7 @@ sigreap(void)
 {
         while (waitpid(-1, NULL, WNOHANG) > 0)
                 ;
+ alarm(TIMEO);
 }
 
 static void
Received on Sun Mar 18 2018 - 14:46:44 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 18 2018 - 14:48:23 CET