do not call signal-unsafe function inside sighanlder
authorNRK <nrk@disroot.org>
Thu, 14 Jul 2022 01:26:40 +0000 (07:26 +0600)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Fri, 15 Jul 2022 18:53:58 +0000 (20:53 +0200)
die() calls vprintf, fputc and exit; none of these are
async-signal-safe, see `man 7 signal-safety`.

dwm.c

diff --git a/dwm.c b/dwm.c
index b3c43eeb23a693a4e734a945cdf3aa31a6d51b86..7c0f9781d44c2db907f059813fbb826b1125da57 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -1541,6 +1541,8 @@ setup(void)
        Atom utf8string;
 
        /* clean up any zombies immediately */
+       if (signal(SIGCHLD, sigchld) == SIG_ERR)
+               die("can't install SIGCHLD handler:");
        sigchld(0);
 
        /* init screen */
@@ -1638,8 +1640,6 @@ showhide(Client *c)
 void
 sigchld(int unused)
 {
-       if (signal(SIGCHLD, sigchld) == SIG_ERR)
-               die("can't install SIGCHLD handler:");
        while (0 < waitpid(-1, NULL, WNOHANG));
 }