Handle sigchld to reap zombies immideately - thingmenu - A simple graphical menu launcher for X11.
 (HTM) git clone git://bitreich.org/thingmenu
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) LICENSE
       ---
 (DIR) commit f3edf619a8441c5ebc5ea4b209770bf30788c137
 (DIR) parent f19ef16ad6c6db0361253620088a5b37b9d0ab4d
 (HTM) Author: Platon Ryzhikov <ihummer63@yandex.ru>
       Date:   Sun, 26 May 2019 17:52:29 +0300
       
       Handle sigchld to reap zombies immideately
       
       Signed-off-by: Christoph Lohmann <20h@r-36.net>
       
       Diffstat:
         M thingmenu.c                         |      17 +++++++++++++----
       
       1 file changed, 13 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/thingmenu.c b/thingmenu.c
       @@ -4,12 +4,12 @@
         */
        #include <unistd.h>
        #include <locale.h>
       +#include <signal.h>
        #include <stdarg.h>
        #include <stdio.h>
        #include <string.h>
        #include <stdlib.h>
        #include <libgen.h>
       -#include <sys/types.h>
        #include <sys/wait.h>
        #include <X11/keysym.h>
        #include <X11/Xatom.h>
       @@ -75,6 +75,7 @@ static void leavenotify(XEvent *e);
        static void press(Entry *e);
        static void run(void);
        static void setup(void);
       +static void sigchld(int unused);
        static int textnw(const char *text, uint len);
        static void unpress(Entry *e);
        static void updateentries(void);
       @@ -423,6 +424,9 @@ setup(void)
                XClassHint *ch;
                int i, sh, sw, ls;
        
       +        /* clean up any zombies immediately */
       +        sigchld(0);
       +
                /* init screen */
                screen = DefaultScreen(dpy);
                root = RootWindow(dpy, screen);
       @@ -510,6 +514,14 @@ setup(void)
                drawmenu();
        }
        
       +void
       +sigchld(int unused)
       +{
       +        if (signal(SIGCHLD, sigchld) == SIG_ERR)
       +                die("can't install SIGCHLD handler:");
       +        while (0 < waitpid(-1, NULL, WNOHANG));
       +}
       +
        int
        textnw(const char *text, uint len)
        {
       @@ -540,9 +552,6 @@ runentry(Entry *e)
        
                        execlp(shell, basename(shell), "-c", e->cmd, (char *)NULL);
                        break;
       -        default:
       -                wait(NULL);
       -                break;
                }
        }