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

From: NRK <nrk_AT_disroot.org>
Date: Wed, 27 Jul 2022 14:42:36 +0600

On Wed, Jul 27, 2022 at 07:36:28AM +0100, Chris Down wrote:
> + sigfillset(&sm);
> + sigprocmask(SIG_SETMASK, &sm, &oldsm);
>
> - /* clean up any zombies immediately */
> - sigchld(0);
> + if (sigaction(SIGCHLD, &sc, NULL) < 0)
> + die("sigaction failed:");
> + /* for zombies inherited before SA_NOCLDWAIT from .xinitrc, etc */
> + while (waitpid(-1, NULL, WNOHANG) > 0);
> +
> + sigprocmask(SIG_SETMASK, &oldsm, NULL);

Just learning about `sigfillset` and `sigprocmask` (and I presume
there's a couple naughty things I'll be able to do with them in the
future =]).

If I understand the manpage correctly, then this patch looks mostly
okay. Only issue I can think of is that both `sigfillset` and
`sigprocmask` manpage states that they may return -1 on errors. So
perhaps they should be error checked just in case:

        if (sigfillset(&sm) < 0 || sigprocmask(SIG_SETMASK, &sm, &oldsm) < 0)
                die("error:");
        /* do the reaping and sighandler installation */
        if (sigprocmask(SIG_SETMASK, &oldsm, NULL) < 0)
                die("error:");

Overall I think this is the right direction, the previous suggestion of
replacing `die` with `write` and `_exit` would still have issues as
pointed out by Roberto [0]

> using signal to reinstall the handler opens a race condition window
> where we can lose sigchld signals and generate zombies process.

[0]: https://lists.suckless.org/hackers/2207/18423.html

- NRK
Received on Wed Jul 27 2022 - 10:42:36 CEST

This archive was generated by hypermail 2.3.0 : Wed Jul 27 2022 - 10:48:29 CEST