From 9d415f313f191530b5aebeef28d1e49d3862c6d1 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 13 Nov 2019 16:44:51 +0100 Subject: [PATCH] syslogd: Add FreeBSD -k option to allow LOG_KERNEL facility messages Signed-off-by: Joachim Nilsson --- man/syslogd.8 | 15 ++++++++++++++- src/Makefile.am | 2 +- src/syslog.c | 4 ---- src/syslogd.c | 9 +++++++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/man/syslogd.8 b/man/syslogd.8 index ee49c82..751bf9a 100644 --- a/man/syslogd.8 +++ b/man/syslogd.8 @@ -13,7 +13,7 @@ .Nd System Log Daemon .Sh SYNOPSIS .Nm -.Op Fl ?46AdnsTv +.Op Fl ?46AdknsTv .Op Fl a Ar addr[/len][:port] .Op Fl a Ar name[:port] .Op Fl b Ar addr[:port] @@ -185,6 +185,19 @@ consecutively. The message is only written if the log file hasn't been touched in .Ar (seconds * 60) / 2 minutes. +.It Fl k +Disable the translation of messages received with facility +.Ql kern +to +facility +.Ql user . +Usually the +.Ql kern +facility is reserved for kernel log messages. When the +.Nm klogd +daemon runs alongside +.Nm , +this option is always set. .It Fl n Run in foreground, required when run from a modern init/supervisor. See your system diff --git a/src/Makefile.am b/src/Makefile.am index a09e500..85f747b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,7 +35,7 @@ syslogd_CPPFLAGS = $(AM_CPPFLAGS) -D_XOPEN_SOURCE=600 syslogd_LDADD = $(LIBS) $(LIBOBJS) klogd_SOURCES = klogd.c klogd.h syslog.h compat.h ksym.c ksyms.h ksym_mod.c module.h -klogd_CPPFLAGS = $(AM_CPPFLAGS) -DALLOW_KERNEL_LOGGING +klogd_CPPFLAGS = $(AM_CPPFLAGS) klogd_LDADD = $(LIBS) $(LIBOBJS) klogd_LDADD += libsyslog.la diff --git a/src/syslog.c b/src/syslog.c index c7f6a0f..0a8d86d 100644 --- a/src/syslog.c +++ b/src/syslog.c @@ -526,11 +526,7 @@ openlog_unlocked_r(const char *ident, int logstat, int logfac, if (ident != NULL) data->log_tag = ident; data->log_stat = logstat; -#ifdef ALLOW_KERNEL_LOGGING - if ((logfac & ~LOG_FACMASK) == 0) -#else if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) -#endif data->log_fac = logfac; if (data->log_stat & LOG_NDELAY) /* open immediately */ diff --git a/src/syslogd.c b/src/syslogd.c index 906647c..056f4cb 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -194,8 +194,8 @@ static int addpeer(struct peer *pe0) int usage(int code) { printf("Usage:\n" - " syslogd [-46Adnrsv?] [-a PEER] [-b :PORT] [-b ADDR[:PORT]] [-f FILE] [-m SEC]\n" - " [-P PID_FILE] [-p SOCK_PATH] [-R SIZE[:NUM]]\n" + " syslogd [-46Adknrsv?] [-a PEER] [-b :PORT] [-b ADDR[:PORT]] [-f FILE] [-m SEC]\n" + " [-P PID_FILE] [-p SOCK_PATH] [-R SIZE[:NUM]]\n" "Options:\n" " -4 Force IPv4 only\n" " -6 Force IPv6 only\n" @@ -222,6 +222,7 @@ int usage(int code) "\n" " -d Enable debug mode\n" " -f FILE Alternate .conf file, default: /etc/syslog.conf\n" + " -k Allow logging with facility 'kernel', otherwise remapped to 'user'.\n" " -m SEC Interval between MARK messages in log, 0 to disable, default: 20 min\n" " -n Run in foreground, required when run from a modern init/supervisor\n" " -P FILE File to store the process ID, default: %s\n" @@ -304,6 +305,10 @@ int main(int argc, char *argv[]) RemoteHostname = 1; break; + case 'k': /* keep remote kern fac */ + KeepKernFac = 1; + break; + case 'm': /* mark interval */ MarkInterval = atoi(optarg) * 60; break;