summaryrefslogtreecommitdiffstats
path: root/term-utils/script.c
diff options
context:
space:
mode:
authorRuediger Meier2015-07-02 12:10:17 +0200
committerKarel Zak2015-07-03 09:53:05 +0200
commit7dbcd80ee8a8079a39c10fc0070ca2f8faa6f09c (patch)
tree5efcdd91ed7226817cda860142b6052fdf94c602 /term-utils/script.c
parentscript: make sure errno is zero (diff)
downloadkernel-qcow2-util-linux-7dbcd80ee8a8079a39c10fc0070ca2f8faa6f09c.tar.gz
kernel-qcow2-util-linux-7dbcd80ee8a8079a39c10fc0070ca2f8faa6f09c.tar.xz
kernel-qcow2-util-linux-7dbcd80ee8a8079a39c10fc0070ca2f8faa6f09c.zip
script: evaluate errno only if read() sets it
[kzak@redhat.com: - be careful with errno and DBG - add EINTR check (both suggested by Rudi] Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'term-utils/script.c')
-rw-r--r--term-utils/script.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/term-utils/script.c b/term-utils/script.c
index 9fdef2e27..b535356a8 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -322,20 +322,17 @@ static void handle_io(struct script_control *ctl, int fd, int *eof)
DBG(IO, ul_debug("%d FD active", fd));
*eof = 0;
- errno = 0;
/* read from active FD */
bytes = read(fd, buf, sizeof(buf));
if (bytes < 0) {
- DBG(IO, ul_debug(" read failed"));
if (errno == EAGAIN || errno == EINTR)
return;
fail(ctl);
}
if (bytes == 0) {
- if (errno == 0)
- *eof = 1;
+ *eof = 1;
return;
}
@@ -367,7 +364,7 @@ static void handle_signal(struct script_control *ctl, int fd)
bytes = read(fd, &info, sizeof(info));
if (bytes != sizeof(info)) {
- if (errno == EAGAIN)
+ if (bytes < 0 && (errno == EAGAIN || errno == EINTR))
return;
fail(ctl);
}
@@ -425,15 +422,17 @@ static void do_io(struct script_control *ctl)
while (!ctl->die) {
size_t i;
+ int errsv;
DBG(POLL, ul_debug("calling poll()"));
/* wait for input or signal */
ret = poll(pfd, ARRAY_SIZE(pfd) - ignore_stdin, ctl->poll_timeout);
+ errsv = errno;
DBG(POLL, ul_debug("poll() rc=%d", ret));
if (ret < 0) {
- if (errno == EAGAIN)
+ if (errsv == EAGAIN)
continue;
warn(_("poll failed"));
fail(ctl);
@@ -463,7 +462,7 @@ static void do_io(struct script_control *ctl)
handle_io(ctl, pfd[i].fd, &eof);
/* EOF maybe detected by two ways:
* A) poll() return POLLHUP event after close()
- * B) read() returns no error and no data */
+ * B) read() returns 0 (no data) */
if ((pfd[i].revents & POLLHUP) || eof) {
DBG(POLL, ul_debug(" ignore FD"));
pfd[i].fd = -1;