passthrough EOF from Terminal to child, plus exit handling - 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 a0cb60891a7420ab2256f238498317569879d4d3
 (DIR) parent c4153df6202b944f947b018d6e461170a3a1168e
 (HTM) Author: Jan Klemkow <j.klemkow@wemelug.de>
       Date:   Tue, 14 Apr 2020 22:14:09 +0200
       
       passthrough EOF from Terminal to child, plus exit handling
       
       Diffstat:
         M scroll.c                            |      14 ++++++++++++--
       
       1 file changed, 12 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/scroll.c b/scroll.c
       @@ -477,8 +477,10 @@ main(int argc, char *argv[])
                        if (pfd[0].revents & POLLIN) {
                                ssize_t n = read(STDIN_FILENO, input, sizeof(input)-1);
        
       -                        if (n <= 0 && errno != EINTR)
       +                        if (n == -1 && errno != EINTR)
                                        die("read:");
       +                        if (n == 0)
       +                                break;
        
                                input[n] = '\0';
        
       @@ -538,5 +540,13 @@ main(int argc, char *argv[])
                        }
                }
        
       -        return EXIT_SUCCESS;
       +        if (close(mfd) == -1)
       +                die("close:");
       +
       +        int status;
       +        while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
       +                if (pid != child)
       +                        continue;
       +
       +        return WEXITSTATUS(status);
        }