From ff96c77dc40bd28cb74baeb1acb79535fb928044 Mon Sep 17 00:00:00 2001 From: Ian Dowse Date: Mon, 26 Jan 2004 00:46:46 +0000 Subject: Be much more strict about parsing tagged log messages from /dev/klog; if the line doesn't match ^<%d>, then treat it as a regular kernel printf line. Previously if a kernel printf message started with "<" it would be interpreted as a log message, often with LOG_EMERG level. This was triggered by some printfs in sys/dev/aic7xxx/, and can also happen with the partial lines that result if syslogd cannot keep up with the rate of arrival of kernel messages. Reviewed by: dwmalone MFC after: 1 week --- usr.sbin/syslogd/syslogd.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index c47dfa9e91de..0acb9ffcc478 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -734,24 +734,34 @@ readklog(void) * Take a raw input line from /dev/klog, format similar to syslog(). */ static void -printsys(char *p) +printsys(char *msg) { - int pri, flags; + char *p; + int flags, isprintf, n, pri; flags = ISKERNEL | SYNC_FILE | ADDDATE; /* fsync after write */ pri = DEFSPRI; + p = msg; + isprintf = 1; if (*p == '<') { - pri = 0; + n = 0; while (isdigit(*++p)) - pri = 10 * pri + (*p - '0'); - if (*p == '>') + n = 10 * n + (*p - '0'); + if (*p == '>') { ++p; - if ((pri & LOG_FACMASK) == LOG_CONSOLE) - flags |= IGN_CONS; - } else { - /* kernel printf's come out on console */ - flags |= IGN_CONS; + pri = n; + isprintf = 0; + } else { + /* It wasn't actually a syslog message. */ + p = msg; + } } + /* + * Kernel printf's and LOG_CONSOLE messages have been displayed + * on the console already. + */ + if (isprintf || (pri & LOG_FACMASK) == LOG_CONSOLE) + flags |= IGN_CONS; if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) pri = DEFSPRI; logmsg(pri, p, LocalHostName, flags); -- cgit v1.2.3