Fix #28: log messages stuck in 1969

The timer_now() API, introduced in 2019, returns time relative to boot.
Useful for relative time comparisons, but when used for absolute time,
e.g. for log messages, it must be offset with boot_time.

This patch fixes issue #28, but also wall messages, which exhibits the
same problem.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2021-05-05 03:25:22 +02:00
parent 4ab8bc7b40
commit eb454d7d37

View File

@ -978,7 +978,7 @@ parsemsg_rfc3164(const char *from, int pri, char *msg)
* This loop can only run for at most three
* iterations before terminating.
*/
t_now = timer_now();
t_now = boot_time + timer_now();
localtime_r(&t_now, &tm_now);
for (year = tm_now.tm_year + 1;; --year) {
assert(year >= tm_now.tm_year - 1);
@ -1765,7 +1765,7 @@ void wallmsg(struct filed *f, struct iovec *iov, int iovcnt)
* and doing notty().
*/
if (fork() == 0) {
time_t t_now = timer_now();
time_t t_now = boot_time + timer_now();
(void)signal(SIGTERM, SIG_DFL);
(void)alarm(0);