From: Thomas Weißschuh Date: Tue, 9 Apr 2024 08:58:19 +0000 (+0200) Subject: logger: handle failures of gettimeofday() X-Git-Tag: v2.42-start~435^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c0137735020c36ce8fb39d731b2acef7e4cb0cd;p=thirdparty%2Futil-linux.git logger: handle failures of gettimeofday() Signed-off-by: Thomas Weißschuh --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index e1d270de8..b4a909438 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),