From 77c092ee5ede9a2642978b9874b3c17e88829fbf Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 25 Jul 2024 17:58:44 +0200 Subject: log: Fetch log times with CLOCK_MONOTONIC, not CLOCK_REALTIME We report relative timestamps in logs, so we want to avoid jumps in the system time. Suggested-by: David Gibson Signed-off-by: Stefano Brivio Reviewed-by: David Gibson --- log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'log.c') diff --git a/log.c b/log.c index 9474bad..0fb25b7 100644 --- a/log.c +++ b/log.c @@ -68,7 +68,7 @@ void vlogmsg(bool newline, int pri, const char *format, va_list ap) struct timespec tp; if (debug_print) { - clock_gettime(CLOCK_REALTIME, &tp); + clock_gettime(CLOCK_MONOTONIC, &tp); fprintf(stderr, logtime_fmt_and_arg(&tp)); fprintf(stderr, ": "); } @@ -382,7 +382,7 @@ void logfile_write(bool newline, int pri, const char *format, va_list ap) char buf[BUFSIZ]; int n; - if (clock_gettime(CLOCK_REALTIME, &now)) + if (clock_gettime(CLOCK_MONOTONIC, &now)) return; n = snprintf(buf, BUFSIZ, logtime_fmt_and_arg(&now)); -- cgit v1.2.3