diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-03 18:31:23 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-03 18:31:23 +0200 |
commit | c5d07fba29a477569a96777c9cab73e53b1ddd5c (patch) | |
tree | 8b7db96623895cf32cd350a894e1654834cec319 /runit | |
parent | 97ef65483a40f8622aaa73408dc0909f01ebd118 (diff) | |
download | busybox-w32-c5d07fba29a477569a96777c9cab73e53b1ddd5c.tar.gz busybox-w32-c5d07fba29a477569a96777c9cab73e53b1ddd5c.tar.bz2 busybox-w32-c5d07fba29a477569a96777c9cab73e53b1ddd5c.zip |
svlogd: do not overrun read buffer (fixes bug 439)
function old new delta
rotate 513 534 +21
logdirs_reopen 1291 1296 +5
processorstart 409 385 -24
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'runit')
-rw-r--r-- | runit/svlogd.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/runit/svlogd.c b/runit/svlogd.c index 25799f6be..79286a3ee 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
@@ -223,7 +223,6 @@ static void processorstart(struct logdir *ld) | |||
223 | while ((pid = vfork()) == -1) | 223 | while ((pid = vfork()) == -1) |
224 | pause2cannot("vfork for processor", ld->name); | 224 | pause2cannot("vfork for processor", ld->name); |
225 | if (!pid) { | 225 | if (!pid) { |
226 | char *prog[4]; | ||
227 | int fd; | 226 | int fd; |
228 | 227 | ||
229 | /* child */ | 228 | /* child */ |
@@ -256,11 +255,7 @@ static void processorstart(struct logdir *ld) | |||
256 | xmove_fd(fd, 5); | 255 | xmove_fd(fd, 5); |
257 | 256 | ||
258 | // getenv("SHELL")? | 257 | // getenv("SHELL")? |
259 | prog[0] = (char*)"sh"; | 258 | execl("/bin/sh", "/bin/sh" + 5, "-c", ld->processor, (char*) NULL); |
260 | prog[1] = (char*)"-c"; | ||
261 | prog[2] = ld->processor; | ||
262 | prog[3] = NULL; | ||
263 | execv("/bin/sh", prog); | ||
264 | bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name); | 259 | bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name); |
265 | } | 260 | } |
266 | ld->fnsave[26] = sv_ch; /* ...restore */ | 261 | ld->fnsave[26] = sv_ch; /* ...restore */ |
@@ -398,13 +393,14 @@ static unsigned rotate(struct logdir *ld) | |||
398 | pause2cannot("rename current", ld->name); | 393 | pause2cannot("rename current", ld->name); |
399 | while ((ld->fdcur = open("current", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600)) == -1) | 394 | while ((ld->fdcur = open("current", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600)) == -1) |
400 | pause2cannot("create new current", ld->name); | 395 | pause2cannot("create new current", ld->name); |
401 | /* we presume this cannot fail */ | 396 | while ((ld->filecur = fdopen(ld->fdcur, "a")) == NULL) //// |
402 | ld->filecur = fdopen(ld->fdcur, "a"); //// | 397 | pause2cannot("create new current", ld->name); /* very unlikely */ |
403 | setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// | 398 | setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// |
404 | close_on_exec_on(ld->fdcur); | 399 | close_on_exec_on(ld->fdcur); |
405 | ld->size = 0; | 400 | ld->size = 0; |
406 | while (fchmod(ld->fdcur, 0644) == -1) | 401 | while (fchmod(ld->fdcur, 0644) == -1) |
407 | pause2cannot("set mode of current", ld->name); | 402 | pause2cannot("set mode of current", ld->name); |
403 | |||
408 | rmoldest(ld); | 404 | rmoldest(ld); |
409 | processorstart(ld); | 405 | processorstart(ld); |
410 | } | 406 | } |
@@ -551,10 +547,11 @@ static unsigned logdir_open(struct logdir *ld, const char *fn) | |||
551 | free(ld->processor); ld->processor = NULL; | 547 | free(ld->processor); ld->processor = NULL; |
552 | 548 | ||
553 | /* read config */ | 549 | /* read config */ |
554 | i = open_read_close("config", buf, sizeof(buf)); | 550 | i = open_read_close("config", buf, sizeof(buf) - 1); |
555 | if (i < 0 && errno != ENOENT) | 551 | if (i < 0 && errno != ENOENT) |
556 | bb_perror_msg(WARNING"%s/config", ld->name); | 552 | bb_perror_msg(WARNING"%s/config", ld->name); |
557 | if (i > 0) { | 553 | if (i > 0) { |
554 | buf[i] = '\0'; | ||
558 | if (verbose) | 555 | if (verbose) |
559 | bb_error_msg(INFO"read: %s/config", ld->name); | 556 | bb_error_msg(INFO"read: %s/config", ld->name); |
560 | s = buf; | 557 | s = buf; |