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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2021-06-21 23:15:10 +02:00
parent 7ce44f5b9e
commit fc5096f1c2

View File

@ -1230,6 +1230,33 @@ void printsys(char *msg)
if (buffer.pri & ~(LOG_FACMASK | LOG_PRIMASK)) if (buffer.pri & ~(LOG_FACMASK | LOG_PRIMASK))
buffer.pri = DEFSPRI; buffer.pri = DEFSPRI;
/*
* Check for user writing to /dev/kmsg before /dev/log
* is up. Syntax to write: <PRI>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; q = lp;
while (*p != '\0' && (c = *p++) != '\n' && q < &line[MAXLINE]) { while (*p != '\0' && (c = *p++) != '\n' && q < &line[MAXLINE]) {
/* Linux /dev/kmsg C-style hex encoding. */ /* Linux /dev/kmsg C-style hex encoding. */