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

From: Michael Forney <mforney_AT_mforney.org>
Date: Sun, 18 Mar 2018 13:09:08 -0700

On 2018-03-18, git_AT_suckless.org <git_AT_suckless.org> wrote:
> 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.

I'm assuming this patch is a response to the bug liwakura reported on
#musl? I also did some investigation of this, and wasn't able to
reproduce the issue on linux.

Were you able to trigger this case somehow (maybe on another OS)?

> 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);

I wonder if there is another way to do this without a timeout. Perhaps
a dedicated reaper thread?

> 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 - 21:09:08 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 18 2018 - 21:12:22 CET