syslogd: Refactor domark() timer handling, always run at TIMERINTVL

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-30 17:55:58 +01:00
parent 77119e2625
commit f4c01a3ba3

View File

@ -136,8 +136,6 @@ static int RemoteHostname; /* Log remote hostname from the message */
static int KeepKernFac; /* Keep remotely logged kernel facility */ static int KeepKernFac; /* Keep remotely logged kernel facility */
static int LastAlarm = 0; /* last value passed to alarm() (seconds) */
static int DupesPending = 0; /* Number of unflushed duplicate messages */
static off_t RotateSz = 0; /* Max file size (bytes) before rotating, disabled by default */ static off_t RotateSz = 0; /* Max file size (bytes) before rotating, disabled by default */
static int RotateCnt = 5; /* Max number (count) of log files to keep, set with -c <NUM> */ static int RotateCnt = 5; /* Max number (count) of log files to keep, set with -c <NUM> */
@ -1261,18 +1259,6 @@ static void logmsg(struct buf_msg *buffer)
f->f_prevcount, now - f->f_time, f->f_prevcount, now - f->f_time,
repeatinterval[f->f_repeatcount]); repeatinterval[f->f_repeatcount]);
if (f->f_prevcount == 1 && DupesPending++ == 0) {
int seconds;
logit("setting alarm to flush duplicate messages\n");
seconds = alarm(0);
MarkSeq += LastAlarm - seconds;
LastAlarm = seconds;
if (LastAlarm > TIMERINTVL || LastAlarm <= 0)
LastAlarm = TIMERINTVL;
alarm(LastAlarm);
}
/* /*
* If domark would have logged this by now, * If domark would have logged this by now,
* flush it now (so we don't hold isolated messages), * flush it now (so we don't hold isolated messages),
@ -1285,19 +1271,9 @@ static void logmsg(struct buf_msg *buffer)
} }
} else { } else {
/* new line, save it */ /* new line, save it */
if (f->f_prevcount) { if (f->f_prevcount)
fprintlog_successive(f, 0); fprintlog_successive(f, 0);
if (--DupesPending == 0) {
logit("unsetting duplicate message flush alarm\n");
MarkSeq += LastAlarm - alarm(0);
LastAlarm = MarkInterval - MarkSeq;
if (LastAlarm > TIMERINTVL || LastAlarm <= 0)
LastAlarm = TIMERINTVL;
alarm(LastAlarm);
}
}
f->f_prevpri = buffer->pri; f->f_prevpri = buffer->pri;
f->f_repeatcount = 0; f->f_repeatcount = 0;
f->f_lasttime = buffer->timestamp; f->f_lasttime = buffer->timestamp;
@ -1950,10 +1926,10 @@ void domark(int signo)
now = time(NULL); now = time(NULL);
if (MarkInterval > 0) { if (MarkInterval > 0) {
MarkSeq += LastAlarm; MarkSeq += TIMERINTVL;
if (MarkSeq >= MarkInterval) { if (MarkSeq >= MarkInterval) {
flog(INTERNAL_MARK | LOG_INFO, "-- MARK --"); flog(INTERNAL_MARK | LOG_INFO, "-- MARK --");
MarkSeq -= MarkInterval; MarkSeq = 0;
} }
} }
@ -1969,15 +1945,10 @@ void domark(int signo)
repeatinterval[f->f_repeatcount]); repeatinterval[f->f_repeatcount]);
fprintlog_successive(f, 0); fprintlog_successive(f, 0);
BACKOFF(f); BACKOFF(f);
DupesPending--;
} }
} }
LastAlarm = MarkInterval - MarkSeq; (void)alarm(TIMERINTVL);
if (LastAlarm > TIMERINTVL || LastAlarm <= 0)
LastAlarm = TIMERINTVL;
(void)alarm(LastAlarm);
} }
void debug_switch(int signo) void debug_switch(int signo)