Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-04-01 20:13:14 +0400
committerDenis Vlasenko <vda.linux@googlemail.com>2008-04-01 20:13:14 +0400
commit9895dfdb9adc55c233bb7945cb8d13bf8044b4b2 (patch)
tree5da860d5e5556aecb86cb1990e6897fd25fe6dd4 /runit/chpst.c
parent9dedf72e7123d028f10dccbb7c5678868e68eb0b (diff)
chpst: fix "env directory" parsing to not strip everything
after 1st whitespace. -6 bytes.
Diffstat (limited to 'runit/chpst.c')
-rw-r--r--runit/chpst.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/runit/chpst.c b/runit/chpst.c
index fcac8ee3c..4de53f051 100644
--- a/runit/chpst.c
+++ b/runit/chpst.c
@@ -114,6 +114,10 @@ static void edir(const char *directory_name)
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 @@ static void edir(const char *directory_name)
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)