From fc5096f1c2b3e23bfd7989eda94978bfcf1224f6 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 21 Jun 2021 23:15:10 +0200 Subject: [PATCH] syslogd: support for extracting user level messages from /dev/kmsg It is well established practise on Linux to use /dev/kmsg (old or new API) before syslogd is up (and /dev/log exists). This patch enables support for extracting non-kernel log messages and logging them with their proper facility and priority. Signed-off-by: Joachim Wiberg --- src/syslogd.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/syslogd.c b/src/syslogd.c index 0788d5d..b23df8d 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -1230,6 +1230,33 @@ void printsys(char *msg) if (buffer.pri & ~(LOG_FACMASK | LOG_PRIMASK)) buffer.pri = DEFSPRI; + /* + * Check for user writing to /dev/kmsg before /dev/log + * is up. Syntax to write: APP_NAME[PROC_ID]:msg + */ + if (buffer.pri & LOG_FACMASK) { + for (q = p; *q && !isspace(*q) && *q != '['; q++) + ; + + if (*q == '[') { + char *ptr = &q[1]; + + while (*ptr && isdigit(*ptr)) + ptr++; + + if (ptr[0] == ']' && ptr[1] == ':') { + *ptr++ = 0; + *q++ = 0; + + buffer.app_name = p; + buffer.proc_id = q; + + /* user log message cont. here */ + p = &ptr[1]; + } + } + } + q = lp; while (*p != '\0' && (c = *p++) != '\n' && q < &line[MAXLINE]) { /* Linux /dev/kmsg C-style hex encoding. */