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

From: NRK <nrk_AT_disroot.org>
Date: Sat, 21 Jan 2023 22:51:18 +0600

On Wed, Jul 27, 2022 at 07:36:28AM +0100, Chris Down wrote:
> -void
> -sigchld(int unused)
> -{
> - if (signal(SIGCHLD, sigchld) == SIG_ERR)
> - die("can't install SIGCHLD handler:");
> - while (0 < waitpid(-1, NULL, WNOHANG));
> -}

One other problem with this type of sighandler that I recently realized
(thanks to Thread-Sanitizer [0]) is that the `waitpid` call may end up
spoiling the `errno`. So when execution resumes, the resuming code can
end up behaving incorrectly due to that.

And as demonstrated in [0] this can occur in practice and is not just a
theoretical issue. Granted that it's much less likely to occur in dwm
since spawning children is done rarely (compared to nsxiv where there
might be upto 2 processes spawned at each image load) but the fact that
crashes like this is possible isn't great to begin with.

If there's any specific issue with Chris' patch which is blocking the
merge then I'd be happy to address them.

[0]: https://codeberg.org/nsxiv/nsxiv/issues/391#issuecomment-776947

- NRK
Received on Sat Jan 21 2023 - 17:51:18 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 21 2023 - 18:00:37 CET