From a2feba69e24bd7df406032054970072448e29a04 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 9 Nov 2019 11:28:34 +0100 Subject: [PATCH] Allow klogd to send LOG_KERN messages to syslogd Signed-off-by: Joachim Nilsson --- src/klogd.c | 15 ++++++++++----- src/syslogd.c | 9 +++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/klogd.c b/src/klogd.c index 4b34372..be40792 100644 --- a/src/klogd.c +++ b/src/klogd.c @@ -43,6 +43,8 @@ #define LOG_BUFFER_SIZE 4096 #define LOG_LINE_LENGTH 1000 +static struct syslog_data log = SYSLOG_DATA_INIT; + static char *PidFile = _PATH_VARRUN "klogd.pid"; static int kmsg; @@ -147,7 +149,7 @@ static void Terminate(void) if (output_file != NULL) fclose(output_file); - closelog(); + closelog_r(&log); exit(1); } @@ -303,13 +305,13 @@ extern void Syslog(int priority, char *fmt, ...) } argl += 3; } - syslog(priority, fmt, argl); + syslog_r(priority, &log, fmt, argl); va_end(ap); return; } va_start(ap, fmt); - vsyslog(priority, fmt, ap); + vsyslog_r(priority, &log, fmt, ap); va_end(ap); } @@ -763,8 +765,11 @@ int main(int argc, char *argv[]) output, strerror(errno)); return 1; } - } else - openlog("kernel", 0, LOG_KERN); + } else { + /* No, I really want to use LOG_KERN */ + log.log_fac = LOG_KERN; + openlog_r("kernel", 0, LOG_KERN, &log); + } /* Handle one-shot logging. */ if (one_shot) { diff --git a/src/syslogd.c b/src/syslogd.c index b4cee55..798cce7 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -233,6 +233,15 @@ int main(int argc, char *argv[]) funix[i] = -1; } +#ifndef WITHOUT_KLOGD + /* + * When building with klogd enabled this works around filtering + * of LOG_KERN messages in parsemsg(). Otherwise it needs to be + * actively enabled to allow logging of remote kernel messages. + */ + KeepKernFac = 1; +#endif + while ((ch = getopt(argc, argv, "46Ab:dhHf:l:m:nP:p:R:rs:v?")) != EOF) { switch ((char)ch) { case '4':