[git commit] libbb: nonblock_safe_read->nonblock_immune_read, remove unused param of xmalloc_reads

Denys Vlasenko vda.linux at googlemail.com
Sun May 8 19:21:10 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=80c5b6893d4708b3683ad9a51c990a326a8f1dff
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/patch.c      |    2 +-
 include/libbb.h      |    4 ++--
 libbb/read_printf.c  |   12 +++++++-----
 mailutils/mail.c     |    4 ++--
 printutils/lpd.c     |    2 +-
 shell/ash.c          |    8 ++++----
 shell/shell_common.c |    2 +-
 util-linux/acpid.c   |    2 +-
 8 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/editors/patch.c b/editors/patch.c
index a90252a..6d3f319 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -239,7 +239,7 @@ static int apply_one_hunk(void)
 	plist = TT.current_hunk;
 	buf = NULL;
 	if (reverse ? TT.oldlen : TT.newlen) for (;;) {
-		char *data = xmalloc_reads(TT.filein, NULL, NULL);
+		char *data = xmalloc_reads(TT.filein, NULL);
 
 		TT.linenum++;
 
diff --git a/include/libbb.h b/include/libbb.h
index 34f7f6a..4ea94e7 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -672,7 +672,7 @@ void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) F
 
 
 extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
-extern ssize_t nonblock_safe_read(int fd, void *buf, size_t count) FAST_FUNC;
+extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
 // NB: will return short read on error, not -1,
 // if some data was read before error occurred
 extern ssize_t full_read(int fd, void *buf, size_t count) FAST_FUNC;
@@ -683,7 +683,7 @@ extern ssize_t open_read_close(const char *filename, void *buf, size_t maxsz) FA
 // Reads one line a-la fgets (but doesn't save terminating '\n').
 // Reads byte-by-byte. Useful when it is important to not read ahead.
 // Bytes are appended to pfx (which must be malloced, or NULL).
-extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC;
+extern char *xmalloc_reads(int fd, size_t *maxsz_p) FAST_FUNC;
 /* Reads block up to *maxsz_p (default: INT_MAX - 4095) */
 extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
 /* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */
diff --git a/libbb/read_printf.c b/libbb/read_printf.c
index 8664bc6..0e6fbf6 100644
--- a/libbb/read_printf.c
+++ b/libbb/read_printf.c
@@ -55,7 +55,7 @@
  * which detects EAGAIN and uses poll() to wait on the fd.
  * Thankfully, poll() doesn't care about O_NONBLOCK flag.
  */
-ssize_t FAST_FUNC nonblock_safe_read(int fd, void *buf, size_t count)
+ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count)
 {
 	struct pollfd pfd[1];
 	ssize_t n;
@@ -74,13 +74,15 @@ ssize_t FAST_FUNC nonblock_safe_read(int fd, void *buf, size_t count)
 // Reads one line a-la fgets (but doesn't save terminating '\n').
 // Reads byte-by-byte. Useful when it is important to not read ahead.
 // Bytes are appended to pfx (which must be malloced, or NULL).
-char* FAST_FUNC xmalloc_reads(int fd, char *buf, size_t *maxsz_p)
+char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p)
 {
 	char *p;
-	size_t sz = buf ? strlen(buf) : 0;
+	char *buf = NULL;
+	size_t sz = 0;
 	size_t maxsz = maxsz_p ? *maxsz_p : (INT_MAX - 4095);
 
 	goto jump_in;
+
 	while (sz < maxsz) {
 		if ((size_t)(p - buf) == sz) {
  jump_in:
@@ -88,8 +90,8 @@ char* FAST_FUNC xmalloc_reads(int fd, char *buf, size_t *maxsz_p)
 			p = buf + sz;
 			sz += 128;
 		}
-		/* nonblock_safe_read() because we are used by e.g. shells */
-		if (nonblock_safe_read(fd, p, 1) != 1) { /* EOF/error */
+		if (nonblock_immune_read(fd, p, 1) != 1) {
+			/* EOF/error */
 			if (p == buf) { /* we read nothing */
 				free(buf);
 				return NULL;
diff --git a/mailutils/mail.c b/mailutils/mail.c
index 4495701..66c7947 100644
--- a/mailutils/mail.c
+++ b/mailutils/mail.c
@@ -172,8 +172,8 @@ void FAST_FUNC get_cred_or_die(int fd)
 		G.user = xstrdup(bb_ask(fd, /* timeout: */ 0, "User: "));
 		G.pass = xstrdup(bb_ask(fd, /* timeout: */ 0, "Password: "));
 	} else {
-		G.user = xmalloc_reads(fd, /* pfx: */ NULL, /* maxsize: */ NULL);
-		G.pass = xmalloc_reads(fd, /* pfx: */ NULL, /* maxsize: */ NULL);
+		G.user = xmalloc_reads(fd, /* maxsize: */ NULL);
+		G.pass = xmalloc_reads(fd, /* maxsize: */ NULL);
 	}
 	if (!G.user || !*G.user || !G.pass)
 		bb_error_msg_and_die("no username or password");
diff --git a/printutils/lpd.c b/printutils/lpd.c
index 115552e..642e8a8 100644
--- a/printutils/lpd.c
+++ b/printutils/lpd.c
@@ -102,7 +102,7 @@ static char *xmalloc_read_stdin(void)
 {
 	// SECURITY:
 	size_t max = 4 * 1024; // more than enough for commands!
-	return xmalloc_reads(STDIN_FILENO, NULL, &max);
+	return xmalloc_reads(STDIN_FILENO, &max);
 }
 
 int lpd_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE;
diff --git a/shell/ash.c b/shell/ash.c
index b50e095..b1b11bd 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5918,7 +5918,7 @@ expbackq(union node *cmd, int quoted, int quotes)
  read:
 		if (in.fd < 0)
 			break;
-		i = nonblock_safe_read(in.fd, buf, sizeof(buf));
+		i = nonblock_immune_read(in.fd, buf, sizeof(buf));
 		TRACE(("expbackq: read returns %d\n", i));
 		if (i <= 0)
 			break;
@@ -9617,7 +9617,7 @@ preadfd(void)
 #if ENABLE_FEATURE_EDITING
  retry:
 	if (!iflag || g_parsefile->pf_fd != STDIN_FILENO)
-		nr = nonblock_safe_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
+		nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
 	else {
 		int timeout = -1;
 # if ENABLE_ASH_IDLE_TIMEOUT
@@ -9663,10 +9663,10 @@ preadfd(void)
 		}
 	}
 #else
-	nr = nonblock_safe_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
+	nr = nonblock_immune_read(g_parsefile->pf_fd, buf, IBUFSIZ - 1);
 #endif
 
-#if 0 /* disabled: nonblock_safe_read() handles this problem */
+#if 0 /* disabled: nonblock_immune_read() handles this problem */
 	if (nr < 0) {
 		if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
 			int flags = fcntl(0, F_GETFL);
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 68659ab..86a6493 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -170,7 +170,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
 
 		if ((bufpos & 0xff) == 0)
 			buffer = xrealloc(buffer, bufpos + 0x100);
-		if (nonblock_safe_read(fd, &buffer[bufpos], 1) != 1) {
+		if (nonblock_immune_read(fd, &buffer[bufpos], 1) != 1) {
 			retval = (const char *)(uintptr_t)1;
 			break;
 		}
diff --git a/util-linux/acpid.c b/util-linux/acpid.c
index c9eed2a..4b7e5ca 100644
--- a/util-linux/acpid.c
+++ b/util-linux/acpid.c
@@ -283,7 +283,7 @@ int acpid_main(int argc UNUSED_PARAM, char **argv)
 				char *buf;
 				int len;
 
-				buf = xmalloc_reads(pfd[i].fd, NULL, NULL);
+				buf = xmalloc_reads(pfd[i].fd, NULL);
 				/* buf = "button/power PWRB 00000080 00000000" */
 				len = strlen(buf) - 9;
 				if (len >= 0)
-- 
1.7.3.4



More information about the busybox-cvs mailing list