svn commit: trunk/busybox/runit

vda at busybox.net vda at busybox.net
Tue Apr 1 16:13:15 UTC 2008


Author: vda
Date: 2008-04-01 09:13:14 -0700 (Tue, 01 Apr 2008)
New Revision: 21615

Log:
chpst: fix "env directory" parsing to not strip everything
after 1st whitespace. -6 bytes.



Modified:
   trunk/busybox/runit/chpst.c


Changeset:
Modified: trunk/busybox/runit/chpst.c
===================================================================
--- trunk/busybox/runit/chpst.c	2008-04-01 16:12:17 UTC (rev 21614)
+++ trunk/busybox/runit/chpst.c	2008-04-01 16:13:14 UTC (rev 21615)
@@ -114,6 +114,10 @@
 	if (!dir)
 		bb_perror_msg_and_die("opendir %s", directory_name);
 	for (;;) {
+		char buf[256];
+		char *tail;
+		int size;
+
 		errno = 0;
 		d = readdir(dir);
 		if (!d) {
@@ -135,31 +139,25 @@
 				bb_perror_msg_and_die("open %s/%s",
 						directory_name, d->d_name);
 		}
-		if (fd >= 0) {
-			char buf[256];
-			char *tail;
-			int size;
-
-			size = safe_read(fd, buf, sizeof(buf)-1);
-			if (size < 0)
-				bb_perror_msg_and_die("read %s/%s",
-						directory_name, d->d_name);
-			if (size == 0) {
-				unsetenv(d->d_name);
-				continue;
-			}
-			buf[size] = '\n';
-			tail = memchr(buf, '\n', sizeof(buf));
-			/* skip trailing whitespace */;
-			while (1) {
-				if (tail[0] == ' ') tail[0] = '\0';
-				if (tail[0] == '\t') tail[0] = '\0';
-				if (tail[0] == '\n') tail[0] = '\0';
-				if (tail == buf) break;
-				tail--;
-			}
-			xsetenv(d->d_name, buf);
+		size = full_read(fd, buf, sizeof(buf)-1);
+		close(fd);
+		if (size < 0)
+			bb_perror_msg_and_die("read %s/%s",
+					directory_name, d->d_name);
+		if (size == 0) {
+			unsetenv(d->d_name);
+			continue;
 		}
+		buf[size] = '\n';
+		tail = strchr(buf, '\n');
+		/* skip trailing whitespace */
+		while (1) {
+			*tail = '\0';
+			tail--;
+			if (tail < buf || !isspace(*tail))
+				break;
+		}
+		xsetenv(d->d_name, buf);
 	}
 	closedir(dir);
 	if (fchdir(wdir) == -1)




More information about the busybox-cvs mailing list