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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2023-07-26 09:14:33 +02:00
parent 91ef7f4d59
commit 45d351065a
2 changed files with 23 additions and 21 deletions

View File

@ -296,7 +296,9 @@ facility is reserved for messages read directly from
Select the number of minutes between Select the number of minutes between
.Dq mark .Dq mark
messages; the default is 20 minutes. Setting this to zero disables log 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 .It Fl n
Disable DNS query for every request. Disable DNS query for every request.
.It Fl p Ar socket .It Fl p Ar socket
@ -622,6 +624,22 @@ from should be put early into the
.Fl a .Fl a
list. list.
.Pp .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 As mentioned in the
.Sx DESCRIPTION , .Sx DESCRIPTION ,
.Nm .Nm

View File

@ -585,13 +585,8 @@ no_klogd:
/* /*
* Set up timer callbacks for -- MARK -- et al * Set up timer callbacks for -- MARK -- et al
*/ */
if (MarkInterval > 0) { if (MarkInterval > 0)
int interval = MarkInterval / 2; timer_add(TIMERINTVL, domark, NULL);
if (interval < 30)
interval = 30;
timer_add(interval, domark, NULL);
}
timer_add(TIMERINTVL, doflush, NULL); timer_add(TIMERINTVL, doflush, NULL);
/* Start 'em */ /* Start 'em */
@ -1674,11 +1669,7 @@ static void logmsg(struct buf_msg *buffer)
/* don't output marks to recently written files */ /* don't output marks to recently written files */
if (buffer->flags & MARK) { if (buffer->flags & MARK) {
time_t t_now = timer_now(); if (timer_now() - f->f_time < MarkInterval)
if (f->f_time + MarkInterval > t_now)
continue;
if (t_now - f->f_time < MarkInterval / 2)
continue; continue;
} }
@ -2423,14 +2414,7 @@ static void forw_lookup(struct filed *f)
void domark(void *arg) 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 --"); flog(INTERNAL_MARK | LOG_INFO, "-- MARK --");
t_last = t_now;
}
} }
void doflush(void *arg) void doflush(void *arg)