From 45d351065a326fb9989d60acbec47a1e4d21a29a Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 26 Jul 2023 09:14:33 +0200 Subject: [PATCH] Fix #37: improve accuracy of MARK timer Instead of running the domark() timer on half the MarkInterval option, we take the FreeBSD approach and run on each TIMERINTVL (30 sec), same as the doflush() timer. This allows greater resolution on the MARK log message, meaning we would be off by < 30 seconds instead of the current MarkInterval / 2. Signed-off-by: Joachim Wiberg --- man/syslogd.8 | 20 +++++++++++++++++++- src/syslogd.c | 24 ++++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/man/syslogd.8 b/man/syslogd.8 index 9a93b8f..dcfb564 100644 --- a/man/syslogd.8 +++ b/man/syslogd.8 @@ -296,7 +296,9 @@ facility is reserved for messages read directly from Select the number of minutes between .Dq mark messages; the default is 20 minutes. Setting this to zero disables log -marks. +marks. See the +.Sx BUGS +section for more information. .It Fl n Disable DNS query for every request. .It Fl p Ar socket @@ -622,6 +624,22 @@ from should be put early into the .Fl a list. .Pp +The mark interval, as controlled by the +.Fl m Ar INTV +option, relies on an internal timer with 30 second granularity. Every +30 seconds +.Nm +will attempt to log the text +.Cd "-- MARK --" +with (the internal) facility +.Cd mark +and priority +.Cd info . +Every log target is traversed, if at least +.Ar INTV +minutes have passed since the log target was written to, the mark is +logged. Hence, it may be off by up to 30 seconds, this is by design. +.Pp As mentioned in the .Sx DESCRIPTION , .Nm diff --git a/src/syslogd.c b/src/syslogd.c index b63e030..0d8a3d7 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -585,13 +585,8 @@ no_klogd: /* * Set up timer callbacks for -- MARK -- et al */ - if (MarkInterval > 0) { - int interval = MarkInterval / 2; - - if (interval < 30) - interval = 30; - timer_add(interval, domark, NULL); - } + if (MarkInterval > 0) + timer_add(TIMERINTVL, domark, NULL); timer_add(TIMERINTVL, doflush, NULL); /* Start 'em */ @@ -1674,11 +1669,7 @@ static void logmsg(struct buf_msg *buffer) /* don't output marks to recently written files */ if (buffer->flags & MARK) { - time_t t_now = timer_now(); - - if (f->f_time + MarkInterval > t_now) - continue; - if (t_now - f->f_time < MarkInterval / 2) + if (timer_now() - f->f_time < MarkInterval) continue; } @@ -2423,14 +2414,7 @@ static void forw_lookup(struct filed *f) void domark(void *arg) { - static time_t t_last = 0; - time_t t_now; - - t_now = timer_now(); - if (t_now >= t_last + MarkInterval) { - flog(INTERNAL_MARK | LOG_INFO, "-- MARK --"); - t_last = t_now; - } + flog(INTERNAL_MARK | LOG_INFO, "-- MARK --"); } void doflush(void *arg)