commit a0cb60891a7420ab2256f238498317569879d4d3
Author:     Jan Klemkow <[email protected]>
AuthorDate: Tue Apr 14 22:14:09 2020 +0200
Commit:     Jan Klemkow <[email protected]>
CommitDate: Tue Apr 14 22:14:09 2020 +0200

    passthrough EOF from Terminal to child, plus exit handling

diff --git a/scroll.c b/scroll.c
index b3946c7..f2e1fd3 100644
--- 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);
 }

Reply via email to