From: Milan Rusek Date: Mon, 20 Feb 2023 09:24:14 +0000 (+0100) Subject: Fix error handling X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=79b041f49b7364807954518646a1d0c27ac2c7bc;p=libucw.git Fix error handling --- diff --git a/ucw/log-file.c b/ucw/log-file.c index deb246a7..48e9cbf9 100644 --- a/ucw/log-file.c +++ b/ucw/log-file.c @@ -146,9 +146,8 @@ log_new_file(const char *path, uint flags) time_t now = time(NULL); struct tm ltm; - if (localtime_r(&now, <m) == NULL) { - ASSERT(0); - } + if (localtime_r(&now, <m) == NULL) + die("Cannot get local time: %m"); do_log_switch(fs, <m); // die()'s on errors return ls; } @@ -158,9 +157,8 @@ log_switch(void) { time_t now = time(NULL); struct tm ltm; - if (localtime_r(&now, <m) == NULL) { - ASSERT(0); - } + if (localtime_r(&now, <m) == NULL) + die("Cannot get local time: %m"); int switched = 0; for (int i=0; i < log_streams_after; i++) diff --git a/ucw/xtypes-extra.c b/ucw/xtypes-extra.c index 0ea28a9f..39d23863 100644 --- a/ucw/xtypes-extra.c +++ b/ucw/xtypes-extra.c @@ -142,17 +142,19 @@ 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 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", <m); + { + struct tm ltm; + if (gmtime_r(&tmp_time, <m) == NULL) + die("Cannot get gmtime: %m"); + strftime(formatted_time_buf, FORMAT_TIME_SIZE, "%F %T", <m); + } break; default: ASSERT(0);