[PATCH] script: evaluate errno only if read() sets it

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ruediger Meier <ruediger.meier@xxxxxxxxxxx>

Signed-off-by: Ruediger Meier <ruediger.meier@xxxxxxxxxxx>
---
 term-utils/script.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 9fdef2e..75881a6 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -322,7 +322,6 @@ 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));
@@ -334,8 +333,7 @@ static void handle_io(struct script_control *ctl, int fd, int *eof)
 	}
 
 	if (bytes == 0) {
-		if (errno == 0)
-			*eof = 1;
+		*eof = 1;
 		return;
 	}
 
@@ -367,7 +365,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)
 			return;
 		fail(ctl);
 	}
@@ -463,7 +461,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;
-- 
1.8.4.5

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux