From 1c0137735020c36ce8fb39d731b2acef7e4cb0cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 9 Apr 2024 10:58:19 +0200 Subject: [PATCH] logger: handle failures of gettimeofday() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- misc-utils/logger.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/misc-utils/logger.c b/misc-utils/logger.c index e1d270de8d..b4a909438b 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -406,12 +406,15 @@ static char const *rfc3164_current_time(void) static char time[32]; struct timeval tv; struct tm tm; + int ret; static char const * const monthnames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - logger_gettimeofday(&tv, NULL); + ret = logger_gettimeofday(&tv, NULL); + if (ret == -1) + err(EXIT_FAILURE, _("gettimeofday() failed")); localtime_r(&tv.tv_sec, &tm); snprintf(time, sizeof(time),"%s %2d %2.2d:%2.2d:%2.2d", monthnames[tm.tm_mon], tm.tm_mday, @@ -782,6 +785,7 @@ static int valid_structured_data_id(const char *str) */ static void syslog_rfc5424_header(struct logger_ctl *const ctl) { + int ret; char *time; char *hostname; char const *app_name = ctl->tag; @@ -794,7 +798,9 @@ static void syslog_rfc5424_header(struct logger_ctl *const ctl) struct timeval tv; struct tm tm; - logger_gettimeofday(&tv, NULL); + ret = logger_gettimeofday(&tv, NULL); + if (ret == -1) + err(EXIT_FAILURE, _("gettimeofday() failed")); if (localtime_r(&tv.tv_sec, &tm) != NULL) { char fmt[64]; const size_t i = strftime(fmt, sizeof(fmt), -- 2.47.3