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>
This commit is contained in:
parent
97ef65483a
commit
c5d07fba29
@ -223,7 +223,6 @@ static void processorstart(struct logdir *ld)
|
|||||||
while ((pid = vfork()) == -1)
|
while ((pid = vfork()) == -1)
|
||||||
pause2cannot("vfork for processor", ld->name);
|
pause2cannot("vfork for processor", ld->name);
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
char *prog[4];
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* child */
|
/* child */
|
||||||
@ -256,11 +255,7 @@ static void processorstart(struct logdir *ld)
|
|||||||
xmove_fd(fd, 5);
|
xmove_fd(fd, 5);
|
||||||
|
|
||||||
// getenv("SHELL")?
|
// getenv("SHELL")?
|
||||||
prog[0] = (char*)"sh";
|
execl("/bin/sh", "/bin/sh" + 5, "-c", ld->processor, (char*) NULL);
|
||||||
prog[1] = (char*)"-c";
|
|
||||||
prog[2] = ld->processor;
|
|
||||||
prog[3] = NULL;
|
|
||||||
execv("/bin/sh", prog);
|
|
||||||
bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name);
|
bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name);
|
||||||
}
|
}
|
||||||
ld->fnsave[26] = sv_ch; /* ...restore */
|
ld->fnsave[26] = sv_ch; /* ...restore */
|
||||||
@ -398,13 +393,14 @@ static unsigned rotate(struct logdir *ld)
|
|||||||
pause2cannot("rename current", ld->name);
|
pause2cannot("rename current", ld->name);
|
||||||
while ((ld->fdcur = open("current", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600)) == -1)
|
while ((ld->fdcur = open("current", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600)) == -1)
|
||||||
pause2cannot("create new current", ld->name);
|
pause2cannot("create new current", ld->name);
|
||||||
/* we presume this cannot fail */
|
while ((ld->filecur = fdopen(ld->fdcur, "a")) == NULL) ////
|
||||||
ld->filecur = fdopen(ld->fdcur, "a"); ////
|
pause2cannot("create new current", ld->name); /* very unlikely */
|
||||||
setvbuf(ld->filecur, NULL, _IOFBF, linelen); ////
|
setvbuf(ld->filecur, NULL, _IOFBF, linelen); ////
|
||||||
close_on_exec_on(ld->fdcur);
|
close_on_exec_on(ld->fdcur);
|
||||||
ld->size = 0;
|
ld->size = 0;
|
||||||
while (fchmod(ld->fdcur, 0644) == -1)
|
while (fchmod(ld->fdcur, 0644) == -1)
|
||||||
pause2cannot("set mode of current", ld->name);
|
pause2cannot("set mode of current", ld->name);
|
||||||
|
|
||||||
rmoldest(ld);
|
rmoldest(ld);
|
||||||
processorstart(ld);
|
processorstart(ld);
|
||||||
}
|
}
|
||||||
@ -551,10 +547,11 @@ static unsigned logdir_open(struct logdir *ld, const char *fn)
|
|||||||
free(ld->processor); ld->processor = NULL;
|
free(ld->processor); ld->processor = NULL;
|
||||||
|
|
||||||
/* read config */
|
/* read config */
|
||||||
i = open_read_close("config", buf, sizeof(buf));
|
i = open_read_close("config", buf, sizeof(buf) - 1);
|
||||||
if (i < 0 && errno != ENOENT)
|
if (i < 0 && errno != ENOENT)
|
||||||
bb_perror_msg(WARNING"%s/config", ld->name);
|
bb_perror_msg(WARNING"%s/config", ld->name);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
buf[i] = '\0';
|
||||||
if (verbose)
|
if (verbose)
|
||||||
bb_error_msg(INFO"read: %s/config", ld->name);
|
bb_error_msg(INFO"read: %s/config", ld->name);
|
||||||
s = buf;
|
s = buf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user