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>2007-11-10 05:01:51 +0300
committerDenis Vlasenko <vda.linux@googlemail.com>2007-11-10 05:01:51 +0300
commit3db254c8866de390c327d759ba615693e45aff6f (patch)
tree1dd0f6a0cc97f1f75a7b88d4488d4919ea2417bd /sysklogd/syslogd.c
parent6cee58e9cfedfa09ede3f5499eb5f635fc2bb77c (diff)
apply accumulated post 1.8.0 fixes, bump version to 1.8.11_8_1
Diffstat (limited to 'sysklogd/syslogd.c')
-rw-r--r--sysklogd/syslogd.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index ba46792b6..da63ced42 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -381,8 +381,8 @@ static void parse_fac_prio_20(int pri, char *res20)
}
/* len parameter is used only for "is there a timestamp?" check.
- * NB: some callers cheat and supply 0 when they know
- * that there is no timestamp, short-cutting the test. */
+ * NB: some callers cheat and supply len==0 when they know
+ * that there is no timestamp, short-circuiting the test. */
static void timestamp_and_log(int pri, char *msg, int len)
{
char *timestamp;
@@ -427,10 +427,10 @@ static void split_escape_and_log(char *tmpbuf, int len)
if (*p == '<') {
/* Parse the magic priority number */
pri = bb_strtou(p + 1, &p, 10);
- if (*p == '>') p++;
- if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) {
+ if (*p == '>')
+ p++;
+ if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
pri = (LOG_USER | LOG_NOTICE);
- }
}
while ((c = *p++)) {
@@ -526,14 +526,32 @@ static void do_syslogd(void)
for (;;) {
size_t sz;
-
+ read_again:
sz = safe_read(sock_fd, G.recvbuf, MAX_READ - 1);
- if (sz <= 0) {
- //if (sz == 0)
- // continue; /* EOF from unix socket??? */
+ if (sz < 0) {
bb_perror_msg_and_die("read from /dev/log");
}
+ /* Drop trailing NULs (typically there is one NUL) */
+ while (1) {
+ if (sz == 0)
+ goto read_again;
+ /* man 3 syslog says: "A trailing newline is added when needed".
+ * However, neither glibc nor uclibc do this:
+ * syslog(prio, "test") sends "test\0" to /dev/log,
+ * syslog(prio, "test\n") sends "test\n\0",
+ * IOW: newline is passed verbatim!
+ * I take it to mean that it's syslogd's job
+ * to make those look identical in the log files */
+ if (G.recvbuf[sz-1] && G.recvbuf[sz-1] != '\n')
+ break;
+ sz--;
+ }
+ /* Maybe we need to add '\n' here, not later?
+ * It looks like stock syslogd does send '\n' over network,
+ * but we do not (see sendto below) */
+ G.recvbuf[sz] = '\0'; /* make sure it *is* NUL terminated */
+
/* TODO: maybe suppress duplicates? */
#if ENABLE_FEATURE_REMOTE_LOG
/* We are not modifying log messages in any way before send */
@@ -549,7 +567,6 @@ static void do_syslogd(void)
}
}
#endif
- G.recvbuf[sz] = '\0';
split_escape_and_log(G.recvbuf, sz);
} /* for */
}