diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-21 01:23:24 +0300 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-21 01:23:24 +0300 |
commit | e376d454bb70ed41bbc3eb0358d37fa30c94358d (patch) | |
tree | eb53c600dcde841a7617a19f819ae3e9cfe7fd84 /shell | |
parent | ae86a338b89c1339588226cb2298e1785aaa7b90 (diff) |
libbb: introduce and use nonblock_safe_read(). Yay!
Our shells are immune from this nasty O_NONBLOCK now!
function old new delta
nonblock_safe_read - 78 +78
file_get 276 295 +19
generateMTFValues 428 435 +7
read_line_input 1776 1772 -4
preadbuffer 543 450 -93
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 104/-97) Total: 7 bytes
text data bss dec hex filename
615190 715 23924 639829 9c355 busybox_old
615168 715 23924 639807 9c33f busybox_unstripped
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 11 | ||||
-rw-r--r-- | shell/hush.c | 8 | ||||
-rw-r--r-- | shell/msh.c | 9 |
3 files changed, 16 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c index 65f94f682..debe8ecdd 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -5428,7 +5428,7 @@ expbackq(union node *cmd, int quoted, int quotes) read: if (in.fd < 0) break; - i = safe_read(in.fd, buf, sizeof(buf)); + i = nonblock_safe_read(in.fd, buf, sizeof(buf)); TRACE(("expbackq: read returns %d\n", i)); if (i <= 0) break; @@ -8678,7 +8678,7 @@ preadfd(void) retry: #if ENABLE_FEATURE_EDITING if (!iflag || parsefile->fd) - nr = safe_read(parsefile->fd, buf, BUFSIZ - 1); + nr = nonblock_safe_read(parsefile->fd, buf, BUFSIZ - 1); else { #if ENABLE_FEATURE_TAB_COMPLETION line_input_state->path_lookup = pathval(); @@ -8700,9 +8700,11 @@ preadfd(void) } } #else - nr = safe_read(parsefile->fd, buf, BUFSIZ - 1); + nr = nonblock_safe_read(parsefile->fd, buf, BUFSIZ - 1); #endif +#if 0 +/* nonblock_safe_read() handles this problem */ if (nr < 0) { if (parsefile->fd == 0 && errno == EWOULDBLOCK) { int flags = fcntl(0, F_GETFL); @@ -8715,6 +8717,7 @@ preadfd(void) } } } +#endif return nr; } @@ -11801,7 +11804,7 @@ readcmd(int argc, char **argv) backslash = 0; STARTSTACKSTR(p); do { - if (read(0, &c, 1) != 1) { + if (nonblock_safe_read(0, &c, 1) != 1) { status = 1; break; } diff --git a/shell/hush.c b/shell/hush.c index 4d4843173..820fd888d 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1273,10 +1273,10 @@ static void get_user_input(struct in_str *i) prompt_str = setup_prompt_string(i->promptmode); #if ENABLE_FEATURE_EDITING /* Enable command line editing only while a command line - * is actually being read; otherwise, we'll end up bequeathing - * atexit() handlers and other unwanted stuff to our - * child processes (rob@sysgo.de) */ - r = read_line_input(prompt_str, user_input_buf, BUFSIZ-1, line_input_state); + * is actually being read */ + do { + r = read_line_input(prompt_str, user_input_buf, BUFSIZ-1, line_input_state); + } while (r == 0); /* repeat if Ctrl-C */ i->eof_flag = (r < 0); if (i->eof_flag) { /* EOF/error detected */ user_input_buf[0] = EOF; /* yes, it will be truncated, it's ok */ diff --git a/shell/msh.c b/shell/msh.c index fd287f16e..917b08a1e 100644 --- a/shell/msh.c +++ b/shell/msh.c @@ -42,6 +42,7 @@ # define xmalloc(size) malloc(size) # define msh_main(argc,argv) main(argc,argv) # define safe_read(fd,buf,count) read(fd,buf,count) +# define nonblock_safe_read(fd,buf,count) read(fd,buf,count) # define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1]) # define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1]) # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) @@ -3376,7 +3377,7 @@ static int doread(struct op *t) } for (wp = t->words + 1; *wp; wp++) { for (cp = global_env.linep; !nl && cp < elinep - 1; cp++) { - nb = read(0, cp, sizeof(*cp)); + nb = nonblock_safe_read(0, cp, sizeof(*cp)); if (nb != sizeof(*cp)) break; nl = (*cp == '\n'); @@ -4799,7 +4800,7 @@ static int filechar(struct ioarg *ap) if (i) lseek(ap->afile, ap->afpos, SEEK_SET); - i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); + i = nonblock_safe_read(ap->afile, bp->buf, sizeof(bp->buf)); if (i <= 0) { closef(ap->afile); return 0; @@ -4830,7 +4831,7 @@ static int filechar(struct ioarg *ap) return c; } #endif - i = safe_read(ap->afile, &c, sizeof(c)); + i = nonblock_safe_read(ap->afile, &c, sizeof(c)); return i == sizeof(c) ? (c & 0x7f) : (closef(ap->afile), 0); } @@ -4841,7 +4842,7 @@ static int herechar(struct ioarg *ap) { char c; - if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) { + if (nonblock_safe_read(ap->afile, &c, sizeof(c)) != sizeof(c)) { close(ap->afile); c = '\0'; } |