From e5d21ecbb3bacb222f1b52d355e6c548021fb3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20J=2E=20Saraiva?= Date: Fri, 5 Apr 2024 13:59:36 +0100 Subject: [PATCH] Change the timestamp to ISO8601 in m_flog. strftime is crashy, it can crash when the timezone is not set. Manually producing an ISO8601 UTC timestamp prevents such crashes. Fixes #84 --- common/utils.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/utils.c b/common/utils.c index bbf2864e7..75d9a30ae 100644 --- a/common/utils.c +++ b/common/utils.c @@ -259,15 +259,13 @@ void m_flog(FILE *fd,char *module,char *fmt,va_list ap) { struct timespec spec; struct tm tmn; - char buf[256]; if (fd != NULL) { clock_gettime(CLOCK_REALTIME, &spec); gmtime_r(&spec.tv_sec, &tmn); - strftime(buf,sizeof(buf),"%b %d %H:%M:%S",&tmn); - - fprintf(fd,"%s.%03ld %s: ",buf,(long)spec.tv_nsec/1000000,module); + // NOTE never use strftime for timestamps, it is crashy + fprintf(fd,"%d-%02d-%02dT%02d:%02d:%02d.%03dZ %s: ",tmn.tm_year+1900,tmn.tm_mon+1,tmn.tm_mday,tmn.tm_hour,tmn.tm_min,tmn.tm_sec,(int)(spec.tv_nsec/1000000),module); vfprintf(fd,fmt,ap); fflush(fd); }