Re: [hackers] Re: [dwm][PATCH v2] Use sigaction(SA_NOCLDWAIT) for SIGCHLD handling

From: NRK <nrk_AT_disroot.org>
Date: Thu, 26 Jan 2023 19:44:08 +0600

On Wed, Jan 25, 2023 at 09:17:53PM +0100, Hiltjo Posthuma wrote:
> Using the new patch it does not handle zombie/defunct processes anymore on this
> machine. To reproduce it, in .xinitrc, on a dusty machine:
>
> sleep 10 &
> exec dwm

For ease of testing I wrote this dummy program. Both SIG_DFL and SIG_IGN
works on my system (glibc 2.36 & linux 5.15.13).

        [/tmp]~> cat test.c
        #include <signal.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <sys/wait.h>
        
        int main(void)
        {
                const struct sigaction sc = {
                        .sa_handler = SIG_DFL,
                        .sa_flags = SA_RESTART | SA_NOCLDWAIT | SA_NOCLDSTOP,
                };
                if (sigaction(SIGCHLD, &sc, NULL) < 0)
                        abort();
                while (waitpid(-1, NULL, WNOHANG) > 0);
                puts("hello there");
                (void)getchar();
        }
        [/tmp]~> cc -o test test.c
        [/tmp]~> cat test.sh
        #!/bin/sh
        
        sleep 4 &
        exec ./test
        [/tmp]~> ./test.sh

And the `signal(3p)` version also works:

        int main(void)
        {
                if (signal(SIGCHLD, SIG_IGN) < 0)
                        abort();
                while (waitpid(-1, NULL, WNOHANG) > 0);
                puts("hello there");
                (void)getchar();
        }

> Also, maybe it is better to not call sigprocmask? Since now it blocks all
> signals, including SIGTERM in setup().

_AT_Chris: I'm looking at the POSIX manpage for sigaction and I don't think
it can fail due to interrupt. Only `EINVAL` is specified:
https://www.man7.org/linux/man-pages/man3/sigaction.3p.html#ERRORS

So getting rid of the `sigprocmask` and manually testing for EINTR when
reaping inherited zombies should be fine, I think.

- NRK
Received on Thu Jan 26 2023 - 14:44:08 CET

This archive was generated by hypermail 2.3.0 : Thu Jan 26 2023 - 14:50:26 CET