Revert upstream commit because of #1549

From 10c0131a8a1b3db7fd6b23b72ebd7b33afc7b018 Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <vda.linux@googlemail.com>
Date: Wed, 11 May 2011 09:49:21 +0000
Subject: hush: use SA_RESTARTed signal handlers across read.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
(limited to 'shell/shell_common.c')
--- shell/shell_common.c
+++ shell/shell_common.c
@@ -167,40 +167,32 @@
 	bufpos = 0;
 	do {
 		char c;
-		struct pollfd pfd[1];
-		int timeout;
 
-		if ((bufpos & 0xff) == 0)
-			buffer = xrealloc(buffer, bufpos + 0x101);
+		errno = 0;
 
-		timeout = -1;
 		if (end_ms) {
-			timeout = end_ms - (unsigned)monotonic_ms();
-			if (timeout <= 0) { /* already late? */
-				retval = (const char *)(uintptr_t)1;
-				goto ret;
-			}
-		}
+			int timeout;
+			struct pollfd pfd[1];
 
-		/* We must poll even if timeout is -1:
-		 * we want to be interrupted if signal arrives,
-		 * regardless of SA_RESTART-ness of that signal!
-		 */
-		errno = 0;
 		pfd[0].fd = fd;
 		pfd[0].events = POLLIN;
-		if (poll(pfd, 1, timeout) != 1) {
-			/* timed out, or EINTR */
+			timeout = end_ms - (unsigned)monotonic_ms();
+			if (timeout <= 0 /* already late? */
+			 || poll(pfd, 1, timeout) != 1 /* no? wait... */
+			) { /* timed out! */
 			err = errno;
 			retval = (const char *)(uintptr_t)1;
 			goto ret;
 		}
-		if (read(fd, &buffer[bufpos], 1) != 1) {
+		}
+
+		if ((bufpos & 0xff) == 0)
+			buffer = xrealloc(buffer, bufpos + 0x100);
+		if (nonblock_immune_read(fd, &buffer[bufpos], 1, /*loop_on_EINTR:*/ 0) != 1) {
 			err = errno;
 			retval = (const char *)(uintptr_t)1;
 			break;
 		}
-
 		c = buffer[bufpos];
 		if (c == '\0')
 			continue;
