aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/read_printf.c8
-rw-r--r--shell/ash.c6
3 files changed, 8 insertions, 8 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 0f8363b78..21da5f100 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -713,7 +713,7 @@ void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) F
713 713
714 714
715extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC; 715extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
716extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count, int loop_on_EINTR) FAST_FUNC; 716extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
717// NB: will return short read on error, not -1, 717// NB: will return short read on error, not -1,
718// if some data was read before error occurred 718// if some data was read before error occurred
719extern ssize_t full_read(int fd, void *buf, size_t count) FAST_FUNC; 719extern ssize_t full_read(int fd, void *buf, size_t count) FAST_FUNC;
diff --git a/libbb/read_printf.c b/libbb/read_printf.c
index 5ed6e3632..b6a17cc36 100644
--- a/libbb/read_printf.c
+++ b/libbb/read_printf.c
@@ -45,20 +45,20 @@
45 * which detects EAGAIN and uses poll() to wait on the fd. 45 * which detects EAGAIN and uses poll() to wait on the fd.
46 * Thankfully, poll() doesn't care about O_NONBLOCK flag. 46 * Thankfully, poll() doesn't care about O_NONBLOCK flag.
47 */ 47 */
48ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count, int loop_on_EINTR) 48ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count)
49{ 49{
50 struct pollfd pfd[1]; 50 struct pollfd pfd[1];
51 ssize_t n; 51 ssize_t n;
52 52
53 while (1) { 53 while (1) {
54 n = loop_on_EINTR ? safe_read(fd, buf, count) : read(fd, buf, count); 54 n = safe_read(fd, buf, count);
55 if (n >= 0 || errno != EAGAIN) 55 if (n >= 0 || errno != EAGAIN)
56 return n; 56 return n;
57 /* fd is in O_NONBLOCK mode. Wait using poll and repeat */ 57 /* fd is in O_NONBLOCK mode. Wait using poll and repeat */
58 pfd[0].fd = fd; 58 pfd[0].fd = fd;
59 pfd[0].events = POLLIN; 59 pfd[0].events = POLLIN;
60 /* note: safe_poll pulls in printf */ 60 /* note: safe_poll pulls in printf */
61 loop_on_EINTR ? safe_poll(pfd, 1, -1) : poll(pfd, 1, -1); 61 safe_poll(pfd, 1, -1);
62 } 62 }
63} 63}
64 64
@@ -81,7 +81,7 @@ char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p)
81 p = buf + sz; 81 p = buf + sz;
82 sz += 128; 82 sz += 128;
83 } 83 }
84 if (nonblock_immune_read(fd, p, 1, /*loop_on_EINTR:*/ 1) != 1) { 84 if (nonblock_immune_read(fd, p, 1) != 1) {
85 /* EOF/error */ 85 /* EOF/error */
86 if (p == buf) { /* we read nothing */ 86 if (p == buf) { /* we read nothing */
87 free(buf); 87 free(buf);
diff --git a/shell/ash.c b/shell/ash.c
index 697a64fea..c51fb804d 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5923,7 +5923,7 @@ expbackq(union node *cmd, int quoted, int quotes)
5923 read: 5923 read:
5924 if (in.fd < 0) 5924 if (in.fd < 0)
5925 break; 5925 break;
5926 i = nonblock_immune_read(in.fd, buf, sizeof(buf), /*loop_on_EINTR:*/ 1); 5926 i = nonblock_immune_read(in.fd, buf, sizeof(buf));
5927 TRACE(("expbackq: read returns %d\n", i)); 5927 TRACE(("expbackq: read returns %d\n", i));
5928 if (i <= 0) 5928 if (i <= 0)
5929 break; 5929 break;
@@ -9696,7 +9696,7 @@ preadfd(void)
9696#if ENABLE_FEATURE_EDITING 9696#if ENABLE_FEATURE_EDITING
9697 retry: 9697 retry:
9698 if (!iflag || g_parsefile->pf_fd != STDIN_FILENO) 9698 if (!iflag || g_parsefile->pf_fd != STDIN_FILENO)
9699 nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1, /*loop_on_EINTR:*/ 1); 9699 nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
9700 else { 9700 else {
9701 int timeout = -1; 9701 int timeout = -1;
9702# if ENABLE_ASH_IDLE_TIMEOUT 9702# if ENABLE_ASH_IDLE_TIMEOUT
@@ -9738,7 +9738,7 @@ preadfd(void)
9738 } 9738 }
9739 } 9739 }
9740#else 9740#else
9741 nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1, /*loop_on_EINTR:*/ 1); 9741 nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
9742#endif 9742#endif
9743 9743
9744#if 0 /* disabled: nonblock_immune_read() handles this problem */ 9744#if 0 /* disabled: nonblock_immune_read() handles this problem */