From ab4478587ac28e7882530a48eadef245cc828d56 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 22 Sep 2019 04:06:03 -0700 Subject: [PATCH] logs: avoid monotonic time lws_now_usecs() uses monotonic time now. It's not sync'd with wallclock time and the two can't be mixed. Switch to gettimeofday which is nonmonotonic and use also for fractional time to avoid fractional secs in logs being unrelated to integer seconds boundary. --- lib/core/logs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/core/logs.c b/lib/core/logs.c index 9e598e031..3b41783fd 100644 --- a/lib/core/logs.c +++ b/lib/core/logs.c @@ -63,16 +63,19 @@ LWS_VISIBLE int lwsl_timestamp(int level, char *p, int len) { #ifndef LWS_PLAT_OPTEE -#ifndef _WIN32_WCE - time_t o_now = time(NULL); -#endif + time_t o_now; unsigned long long now; + struct timeval tv; struct tm *ptm = NULL; #ifndef WIN32 struct tm tm; #endif int n; + gettimeofday(&tv, NULL); + o_now = tv.tv_sec; + now = ((unsigned long long)tv.tv_sec * 10000) + (tv.tv_usec / 100); + #ifndef _WIN32_WCE #ifdef WIN32 ptm = localtime(&o_now);