summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2014-01-16 12:22:13 +0100
committerKarel Zak2014-01-16 12:22:13 +0100
commit38374be4c857bfe2129d278e81fe4ed505ef0077 (patch)
tree73f1b4ab3dccd8f06fdf18ca68d520366a546dec
parentpartx: use blkid_partlist_get_partition_by_partno() (diff)
downloadkernel-qcow2-util-linux-38374be4c857bfe2129d278e81fe4ed505ef0077.tar.gz
kernel-qcow2-util-linux-38374be4c857bfe2129d278e81fe4ed505ef0077.tar.xz
kernel-qcow2-util-linux-38374be4c857bfe2129d278e81fe4ed505ef0077.zip
script: don't wait for empty descriptors if child is dead
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>
-rw-r--r--term-utils/script.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/term-utils/script.c b/term-utils/script.c
index 277499d5b..70f590159 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -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();
}