]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
script: don't wait for empty descriptors if child is dead
authorKarel Zak <kzak@redhat.com>
Thu, 16 Jan 2014 11:22:13 +0000 (12:22 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 16 Jan 2014 11:22:13 +0000 (12:22 +0100)
The current code waits for empty file master and slave descriptors,
but it makes sense only if there is child process that cares (read)
about data in the descriptors.

Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/script.c

index 277499d5b94de8f133adf7cf90dba6edf0c200c8..70f5901593562f4a28676459711cefb9ff12476b 100644 (file)
@@ -302,11 +302,12 @@ static void wait_for_empty_fd(int fd)
                { .fd = fd, .events = POLLIN }
        };
 
-       while (poll(fds, 1, 50) == 1);
+       while (die == 0 && poll(fds, 1, 100) == 1);
 }
 
 void
 doinput(void) {
+       int errsv = 0;
        ssize_t cc = 0;
        char ibuf[BUFSIZ];
 
@@ -330,15 +331,17 @@ doinput(void) {
                        }
                        resized = 0;
 
-               } else
+               } else {
+                       errsv = errno;
                        break;
+               }
        }
 
        /* To be sure that we don't miss any data */
        wait_for_empty_fd(slave);
        wait_for_empty_fd(master);
 
-       if (cc == 0 && errno == 0) {
+       if (die == 0 && cc == 0 && errsv == 0) {
                /*
                 * Forward EOF from stdin (detected by read() above) to slave
                 * (shell) to correctly terminate the session. It seems we have
@@ -360,7 +363,8 @@ doinput(void) {
                wait_for_empty_fd(master);
        }
 
-       finish(0);      /* wait for childern */
+       if (!die)
+               finish(0);      /* wait for childern */
        done();
 }