]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: handle failures of gettimeofday()
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 9 Apr 2024 08:58:19 +0000 (10:58 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 9 Apr 2024 09:00:45 +0000 (11:00 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
misc-utils/logger.c

index e1d270de8df6782bc5c801c185e6f53ea14e5e9b..b4a909438b30763e1f15133d2b7e3b01ac98f296 100644 (file)
@@ -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),