[PATCH] Fix runsvdir so it reaps children and avoid zombi processes when killed.

Denys Vlasenko vda.linux at googlemail.com
Sun Jan 7 00:34:56 UTC 2018


On Thu, Jan 4, 2018 at 4:03 PM, Laurent Bercot <ska-dietlibc at skarnet.org> wrote:
>> Please point out the code in init.c which you think is buggy.
>
>
>  https://git.busybox.net/busybox/tree/init/init.c#n1216 is buggy.
>
>  Unconditionally sleeping when signals may arrive is a no-no. If
> a child dies right before this line, or during the sleep, init will
> not handle the signal immediately. It will sleep the full second, and
> only handle the signal - and reap the zombie - after the sleep is done.

It depends whether you consider init to be required to reap zombies
as fast as possible.

I don't see that as a requirement (so far, feel free to convince
me otherwise).

>  The way to fix this is to completely redesign the loop. Currently
> it's a mess of two nested loops with several check_delayed_sigs()
> calls inside - no matter how many you have, it's still racy.
> The proper way to design the loop is to have a single loop, not a
> nested one, with either a self-pipe to handle signals, or a
> pselect()/ppoll() call with a signal mask.

Currently, the sleep(1) is there to prevent a buggy "respawn"
child which exits immediately from consuming 100% CPU.

Just delete these lines:

                /* Don't consume all CPU time - sleep a bit */
                sleep(1);
                maybe_WNOHANG |= check_delayed_sigs();

and it will start reaping all zombies at once.


More information about the busybox mailing list