From e381bc36204bc6d7997b49cf761b6b22912488b3 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 30 Jun 2021 22:39:09 +0200 Subject: [PATCH] Fix #38: add option `-C file` for alt. kernel seqno cache file Signed-off-by: Joachim Wiberg --- man/syslogd.8 | 11 +++++++++++ src/syslogd.c | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/man/syslogd.8 b/man/syslogd.8 index eb298b6..a123cc9 100644 --- a/man/syslogd.8 +++ b/man/syslogd.8 @@ -43,6 +43,7 @@ .Op Fl a Ar name[:port] .Op Fl b Ar addr[:port] .Op Fl b Ar :port +.Op Fl C Ar file .Op Fl f Ar file .Op Fl m Ar interval .Op Fl P Ar file @@ -209,6 +210,16 @@ is .Ql syslog . This option can be specified multiple times to bind to multiple addresses and/or ports. +.It Fl C Ar file +File to use for caching last read kernel sequence number from +.Pa /dev/kmsg , +default: +.Pa /run/syslogd.cache . +If +.Nm +cannot write to, or read from, this file it will cause repeated kernel +log messages when restarting +.Nm . .It Fl d Put .Nm diff --git a/src/syslogd.c b/src/syslogd.c index 832e0e0..d73f079 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -96,9 +96,10 @@ static char sccsid[] __attribute__((unused)) = #include "timer.h" #include "compat.h" -char *ConfFile = _PATH_LOGCONF; -char *PidFile = _PATH_LOGPID; -char ctty[] = _PATH_CONSOLE; +char *CacheFile = _PATH_CACHE; +char *ConfFile = _PATH_LOGCONF; +char *PidFile = _PATH_LOGPID; +char ctty[] = _PATH_CONSOLE; static volatile sig_atomic_t debugging_on; static volatile sig_atomic_t restart; @@ -202,7 +203,7 @@ static void sys_seqno_load(void) char buf[32], *str; FILE *fp; - fp = fopen(_PATH_CACHE, "r"); + fp = fopen(CacheFile, "r"); if (!fp) return; @@ -235,7 +236,7 @@ static void sys_seqno_save(void) if (prev == sys_seqno) return; /* no changes since last save */ - fp = fopen(_PATH_CACHE, "w"); + fp = fopen(CacheFile, "w"); if (!fp) return; /* best effort, ignore any errors */ @@ -273,6 +274,7 @@ int usage(int code) " :port UDP port number, or service name\n" " default: 'syslog', port 514\n" "\n" + " -C FILE File to cache last read kernel seqno, default: %s\n" " -d Enable debug mode, implicitly enables -F to prevent backgrounding\n" " -F Run in foreground, required when monitored by init(1)\n" " -f FILE Alternate .conf file, default: %s\n" @@ -293,7 +295,7 @@ int usage(int code) " -v Show program version and exit\n" "\n" "Bug report address: %s\n", - _PATH_LOGCONF, _PATH_LOGPID, _PATH_LOG, _PATH_LOGCONF, PACKAGE_BUGREPORT); + _PATH_CACHE, _PATH_LOGCONF, _PATH_LOGPID, _PATH_LOG, _PATH_LOGCONF, PACKAGE_BUGREPORT); #ifdef PACKAGE_URL printf("Project home page: %s\n", PACKAGE_URL); #endif @@ -308,7 +310,7 @@ int main(int argc, char *argv[]) int pflag = 0, bflag = 0; int ch; - while ((ch = getopt(argc, argv, "46Aa:b:dHFf:km:nP:p:r:sTv?")) != EOF) { + while ((ch = getopt(argc, argv, "46Aa:b:C:dHFf:km:nP:p:r:sTv?")) != EOF) { switch ((char)ch) { case '4': family = PF_INET; @@ -338,6 +340,10 @@ int main(int argc, char *argv[]) }); break; + case 'C': /* kernel seqno cache file */ + CacheFile = optarg; + break; + case 'd': /* debug */ Debug = 1; Foreground = 1;