summaryrefslogtreecommitdiff
path: root/sysklogd/syslogd.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-11-06 01:38:46 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-11-06 01:38:46 +0000
commit018b155ad938ed9a1867214e13b166495599d222 (patch)
treecb6b553062b365af521fc27159efa812da59f0bf /sysklogd/syslogd.c
parentcb981638f502f4cc5ea830edc7ef62ab71112186 (diff)
downloadbusybox-w32-018b155ad938ed9a1867214e13b166495599d222.tar.gz
busybox-w32-018b155ad938ed9a1867214e13b166495599d222.tar.bz2
busybox-w32-018b155ad938ed9a1867214e13b166495599d222.zip
telnetd: fix problem with zombies (by Paul Fox <pgf@brightstareng.com>)
syslogd: strip trailing NULs
Diffstat (limited to 'sysklogd/syslogd.c')
-rw-r--r--sysklogd/syslogd.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index ba46792b6..2bf5b5c80 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -381,8 +381,8 @@ static void parse_fac_prio_20(int pri, char *res20)
381} 381}
382 382
383/* len parameter is used only for "is there a timestamp?" check. 383/* len parameter is used only for "is there a timestamp?" check.
384 * NB: some callers cheat and supply 0 when they know 384 * NB: some callers cheat and supply len==0 when they know
385 * that there is no timestamp, short-cutting the test. */ 385 * that there is no timestamp, short-circuiting the test. */
386static void timestamp_and_log(int pri, char *msg, int len) 386static void timestamp_and_log(int pri, char *msg, int len)
387{ 387{
388 char *timestamp; 388 char *timestamp;
@@ -427,10 +427,10 @@ static void split_escape_and_log(char *tmpbuf, int len)
427 if (*p == '<') { 427 if (*p == '<') {
428 /* Parse the magic priority number */ 428 /* Parse the magic priority number */
429 pri = bb_strtou(p + 1, &p, 10); 429 pri = bb_strtou(p + 1, &p, 10);
430 if (*p == '>') p++; 430 if (*p == '>')
431 if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) { 431 p++;
432 if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
432 pri = (LOG_USER | LOG_NOTICE); 433 pri = (LOG_USER | LOG_NOTICE);
433 }
434 } 434 }
435 435
436 while ((c = *p++)) { 436 while ((c = *p++)) {
@@ -526,14 +526,22 @@ static void do_syslogd(void)
526 526
527 for (;;) { 527 for (;;) {
528 size_t sz; 528 size_t sz;
529 529 read_again:
530 sz = safe_read(sock_fd, G.recvbuf, MAX_READ - 1); 530 sz = safe_read(sock_fd, G.recvbuf, MAX_READ - 1);
531 if (sz <= 0) { 531 if (sz < 0) {
532 //if (sz == 0)
533 // continue; /* EOF from unix socket??? */
534 bb_perror_msg_and_die("read from /dev/log"); 532 bb_perror_msg_and_die("read from /dev/log");
535 } 533 }
536 534
535 /* Drop trailing NULs (typically there is one NUL) */
536 while (1) {
537 if (sz == 0)
538 goto read_again;
539 if (G.recvbuf[sz-1])
540 break;
541 sz--;
542 }
543 G.recvbuf[sz] = '\0'; /* make sure it *is* NUL terminated */
544
537 /* TODO: maybe suppress duplicates? */ 545 /* TODO: maybe suppress duplicates? */
538#if ENABLE_FEATURE_REMOTE_LOG 546#if ENABLE_FEATURE_REMOTE_LOG
539 /* We are not modifying log messages in any way before send */ 547 /* We are not modifying log messages in any way before send */
@@ -549,7 +557,6 @@ static void do_syslogd(void)
549 } 557 }
550 } 558 }
551#endif 559#endif
552 G.recvbuf[sz] = '\0';
553 split_escape_and_log(G.recvbuf, sz); 560 split_escape_and_log(G.recvbuf, sz);
554 } /* for */ 561 } /* for */
555} 562}