handle child exit via POLLHUP instead of sigchld - scroll - scrollbackbuffer program for st
 (HTM) git clone git://git.suckless.org/scroll
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 97b90414891e957c95caffe078c69b18aa38e659
 (DIR) parent d10c029b182fef1af4c6ec2713f9a8a3a5245edb
 (HTM) Author: Jan Klemkow <j.klemkow@wemelug.de>
       Date:   Fri, 17 Apr 2020 21:46:55 +0200
       
       handle child exit via POLLHUP instead of sigchld
       
       this fix a racecondition which leads to wrong return code.
       
       Diffstat:
         M scroll.c                            |      21 ++-------------------
       
       1 file changed, 2 insertions(+), 19 deletions(-)
       ---
 (DIR) diff --git a/scroll.c b/scroll.c
       @@ -90,19 +90,6 @@ die(const char *fmt, ...)
        }
        
        void
       -sigchld(int sig)
       -{
       -        pid_t pid;
       -        int status;
       -
       -        assert(sig == SIGCHLD);
       -
       -        while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
       -                if (pid == child)
       -                        exit(WEXITSTATUS(status));
       -}
       -
       -void
        sigwinch(int sig)
        {
                assert(sig == SIGWINCH);
       @@ -421,8 +408,6 @@ main(int argc, char *argv[])
                if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
                        die("ioctl:");
        
       -        if (signal(SIGCHLD, sigchld) == SIG_ERR)
       -                die("signal:");
                if (signal(SIGWINCH, sigwinch) == SIG_ERR)
                        die("signal:");
        
       @@ -553,11 +538,9 @@ main(int argc, char *argv[])
                if (close(mfd) == -1)
                        die("close:");
        
       -        pid_t pid;
                int status;
       -        while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
       -                if (pid != child)
       -                        continue;
       +        if (waitpid(child, &status, 0) == -1)
       +                die("waitpid:");
        
                return WEXITSTATUS(status);
        }