]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/logger.c
Merge branch 'uuidv7' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / misc-utils / logger.c
index b4a909438b30763e1f15133d2b7e3b01ac98f296..f696287d7a6b8b21c57cc1afe42962a70913e0c7 100644 (file)
@@ -154,13 +154,24 @@ static inline int logger_gettimeofday(struct timeval *tv, struct timezone *tz)
        char *str = getenv("LOGGER_TEST_TIMEOFDAY");
        uintmax_t sec, usec;
 
-       if (str && sscanf(str, "%ju.%ju", &sec, &usec) == 2) {
+       if (str) {
+               if (sscanf(str, "%ju.%ju", &sec, &usec) != 2)
+                       goto err;
+
                tv->tv_sec = sec;
                tv->tv_usec = usec;
-               return tv->tv_sec >= 0 && tv->tv_usec >= 0 ? 0 : -EINVAL;
+
+               if (tv->tv_sec >= 0 && tv->tv_usec >= 0)
+                       return 0;
+               else
+                       goto err;
        }
 
        return gettimeofday(tv, tz);
+
+err:
+       errno = EINVAL;
+       return -1;
 }
 
 static inline char *logger_xgethostname(void)
@@ -804,12 +815,12 @@ static void syslog_rfc5424_header(struct logger_ctl *const ctl)
                if (localtime_r(&tv.tv_sec, &tm) != NULL) {
                        char fmt[64];
                        const size_t i = strftime(fmt, sizeof(fmt),
-                                                 "%Y-%m-%dT%H:%M:%S.%%06u%z ", &tm);
+                                                 "%Y-%m-%dT%H:%M:%S.%%06jd%z ", &tm);
                        /* patch TZ info to comply with RFC3339 (we left SP at end) */
                        fmt[i - 1] = fmt[i - 2];
                        fmt[i - 2] = fmt[i - 3];
                        fmt[i - 3] = ':';
-                       xasprintf(&time, fmt, tv.tv_usec);
+                       xasprintf(&time, fmt, (intmax_t) tv.tv_usec);
                } else
                        err(EXIT_FAILURE, _("localtime() failed"));
        } else