diff options
author | Thomas Weißschuh <thomas@t-8ch.de> | 2024-04-09 10:58:19 +0200 |
---|---|---|
committer | Thomas Weißschuh <thomas@t-8ch.de> | 2024-04-09 11:00:45 +0200 |
commit | 1c0137735020c36ce8fb39d731b2acef7e4cb0cd (patch) | |
tree | caac23ce4b914372b9fb3996767e759f36c27d28 | |
parent | 07aacb371470b5561f13b95e399e5ff77e417b8f (diff) | |
download | util-linux-1c0137735020c36ce8fb39d731b2acef7e4cb0cd.tar.gz |
logger: handle failures of gettimeofday()
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
-rw-r--r-- | misc-utils/logger.c | 10 |
1 files 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), |