aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-05-08 21:23:43 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-05-08 21:23:43 +0200
commit80542bad2f1df9d99b579c9eeb3c2675c14c72c0 (patch)
tree906cdea5609e0272fda16dc02caa3c683912c228 /libbb
parent80c5b6893d4708b3683ad9a51c990a326a8f1dff (diff)
downloadbusybox-w32-80542bad2f1df9d99b579c9eeb3c2675c14c72c0.tar.gz
busybox-w32-80542bad2f1df9d99b579c9eeb3c2675c14c72c0.tar.bz2
busybox-w32-80542bad2f1df9d99b579c9eeb3c2675c14c72c0.zip
hush: make read builtin interruptible.
function old new delta builtin_read 185 471 +286 check_and_run_traps 200 262 +62 nonblock_immune_read 73 119 +46 sigismember - 44 +44 record_signal - 21 +21 sigisemptyset - 16 +16 ... ------------------------------------------------------------------------------ (add/remove: 5/0 grow/shrink: 7/5 up/down: 483/-46) Total: 437 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/read_printf.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libbb/read_printf.c b/libbb/read_printf.c
index 0e6fbf662..192f83d6e 100644
--- a/libbb/read_printf.c
+++ b/libbb/read_printf.c
@@ -55,19 +55,20 @@
55 * which detects EAGAIN and uses poll() to wait on the fd. 55 * which detects EAGAIN and uses poll() to wait on the fd.
56 * Thankfully, poll() doesn't care about O_NONBLOCK flag. 56 * Thankfully, poll() doesn't care about O_NONBLOCK flag.
57 */ 57 */
58ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count) 58ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count, int loop_on_EINTR)
59{ 59{
60 struct pollfd pfd[1]; 60 struct pollfd pfd[1];
61 ssize_t n; 61 ssize_t n;
62 62
63 while (1) { 63 while (1) {
64 n = safe_read(fd, buf, count); 64 n = loop_on_EINTR ? safe_read(fd, buf, count) : read(fd, buf, count);
65 if (n >= 0 || errno != EAGAIN) 65 if (n >= 0 || errno != EAGAIN)
66 return n; 66 return n;
67 /* fd is in O_NONBLOCK mode. Wait using poll and repeat */ 67 /* fd is in O_NONBLOCK mode. Wait using poll and repeat */
68 pfd[0].fd = fd; 68 pfd[0].fd = fd;
69 pfd[0].events = POLLIN; 69 pfd[0].events = POLLIN;
70 safe_poll(pfd, 1, -1); /* note: this pulls in printf */ 70 /* note: safe_poll pulls in printf */
71 loop_on_EINTR ? safe_poll(pfd, 1, -1) : poll(pfd, 1, -1);
71 } 72 }
72} 73}
73 74
@@ -90,7 +91,7 @@ char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p)
90 p = buf + sz; 91 p = buf + sz;
91 sz += 128; 92 sz += 128;
92 } 93 }
93 if (nonblock_immune_read(fd, p, 1) != 1) { 94 if (nonblock_immune_read(fd, p, 1, /*loop_on_EINTR:*/ 1) != 1) {
94 /* EOF/error */ 95 /* EOF/error */
95 if (p == buf) { /* we read nothing */ 96 if (p == buf) { /* we read nothing */
96 free(buf); 97 free(buf);