diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-01 16:13:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-01 16:13:14 +0000 |
commit | 9895dfdb9adc55c233bb7945cb8d13bf8044b4b2 (patch) | |
tree | 5da860d5e5556aecb86cb1990e6897fd25fe6dd4 | |
parent | 9dedf72e7123d028f10dccbb7c5678868e68eb0b (diff) | |
download | busybox-w32-9895dfdb9adc55c233bb7945cb8d13bf8044b4b2.tar.gz busybox-w32-9895dfdb9adc55c233bb7945cb8d13bf8044b4b2.tar.bz2 busybox-w32-9895dfdb9adc55c233bb7945cb8d13bf8044b4b2.zip |
chpst: fix "env directory" parsing to not strip everything
after 1st whitespace. -6 bytes.
-rw-r--r-- | runit/chpst.c | 46 |
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) | |||
114 | if (!dir) | 114 | if (!dir) |
115 | bb_perror_msg_and_die("opendir %s", directory_name); | 115 | bb_perror_msg_and_die("opendir %s", directory_name); |
116 | for (;;) { | 116 | for (;;) { |
117 | char buf[256]; | ||
118 | char *tail; | ||
119 | int size; | ||
120 | |||
117 | errno = 0; | 121 | errno = 0; |
118 | d = readdir(dir); | 122 | d = readdir(dir); |
119 | if (!d) { | 123 | if (!d) { |
@@ -135,31 +139,25 @@ static void edir(const char *directory_name) | |||
135 | bb_perror_msg_and_die("open %s/%s", | 139 | bb_perror_msg_and_die("open %s/%s", |
136 | directory_name, d->d_name); | 140 | directory_name, d->d_name); |
137 | } | 141 | } |
138 | if (fd >= 0) { | 142 | size = full_read(fd, buf, sizeof(buf)-1); |
139 | char buf[256]; | 143 | close(fd); |
140 | char *tail; | 144 | if (size < 0) |
141 | int size; | 145 | bb_perror_msg_and_die("read %s/%s", |
142 | 146 | directory_name, d->d_name); | |
143 | size = safe_read(fd, buf, sizeof(buf)-1); | 147 | if (size == 0) { |
144 | if (size < 0) | 148 | unsetenv(d->d_name); |
145 | bb_perror_msg_and_die("read %s/%s", | 149 | continue; |
146 | directory_name, d->d_name); | 150 | } |
147 | if (size == 0) { | 151 | buf[size] = '\n'; |
148 | unsetenv(d->d_name); | 152 | tail = strchr(buf, '\n'); |
149 | continue; | 153 | /* skip trailing whitespace */ |
150 | } | 154 | while (1) { |
151 | buf[size] = '\n'; | 155 | *tail = '\0'; |
152 | tail = memchr(buf, '\n', sizeof(buf)); | 156 | tail--; |
153 | /* skip trailing whitespace */; | 157 | if (tail < buf || !isspace(*tail)) |
154 | while (1) { | 158 | break; |
155 | if (tail[0] == ' ') tail[0] = '\0'; | ||
156 | if (tail[0] == '\t') tail[0] = '\0'; | ||
157 | if (tail[0] == '\n') tail[0] = '\0'; | ||
158 | if (tail == buf) break; | ||
159 | tail--; | ||
160 | } | ||
161 | xsetenv(d->d_name, buf); | ||
162 | } | 159 | } |
160 | xsetenv(d->d_name, buf); | ||
163 | } | 161 | } |
164 | closedir(dir); | 162 | closedir(dir); |
165 | if (fchdir(wdir) == -1) | 163 | if (fchdir(wdir) == -1) |