From: Milan Rusek Date: Fri, 17 Feb 2023 05:37:18 +0000 (+0100) Subject: Fix localtime to localtime_r and gmtime to gmtime_r X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=2774f104f31ebde6c7c75cee7aecd11f1dc68686;p=libucw.git Fix localtime to localtime_r and gmtime to gmtime_r --- diff --git a/ucw/log-file.c b/ucw/log-file.c index 2e7a8d26..deb246a7 100644 --- a/ucw/log-file.c +++ b/ucw/log-file.c @@ -145,9 +145,11 @@ log_new_file(const char *path, uint flags) ls->close = file_close; time_t now = time(NULL); - struct tm *tm = localtime(&now); - ASSERT(tm); - do_log_switch(fs, tm); // die()'s on errors + struct tm ltm; + if (localtime_r(&now, <m) == NULL) { + ASSERT(0); + } + do_log_switch(fs, <m); // die()'s on errors return ls; } @@ -155,13 +157,15 @@ int log_switch(void) { time_t now = time(NULL); - struct tm *tm = localtime(&now); - ASSERT(tm); + struct tm ltm; + if (localtime_r(&now, <m) == NULL) { + ASSERT(0); + } int switched = 0; for (int i=0; i < log_streams_after; i++) if (log_streams.ptr[i]->handler == file_handler) - switched |= do_log_switch((struct file_stream *) log_streams.ptr[i], tm); + switched |= do_log_switch((struct file_stream *) log_streams.ptr[i], <m); return switched; } diff --git a/ucw/xtypes-extra.c b/ucw/xtypes-extra.c index c0c31a83..0ea28a9f 100644 --- a/ucw/xtypes-extra.c +++ b/ucw/xtypes-extra.c @@ -142,14 +142,17 @@ static const char *xt_timestamp_format(void *src, u32 fmt, struct mempool *pool) u64 tmp_time_u64 = *(u64*)src; time_t tmp_time = (time_t) tmp_time_u64; - struct tm t = *gmtime(&tmp_time); + struct tm ltm; + if (gmtime_r(&tmp_time, <m) == NULL) { + ASSERT(0); + } switch (fmt) { case XTYPE_FMT_DEFAULT: case XTYPE_FMT_RAW: sprintf(formatted_time_buf, "%"PRIu64, tmp_time_u64); break; case XTYPE_FMT_PRETTY: - strftime(formatted_time_buf, FORMAT_TIME_SIZE, "%F %T", &t); + strftime(formatted_time_buf, FORMAT_TIME_SIZE, "%F %T", <m); break; default: ASSERT(0);