]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal/journald-console: fix format-specifier issue
authorJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Wed, 22 Mar 2017 20:34:32 +0000 (21:34 +0100)
committerJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Fri, 19 May 2017 12:23:22 +0000 (14:23 +0200)
timespec::tv_nsec can have different sizes depending on the
host architecture. On x32 in particular, it is 8 bytes long
while the long int type is only 4 bytes long. Hence, using
ld as a format specifier will trigger a format error. Thus,
explicitly cast timespec::tv_nsec to nsec_t and use PRI_NSEC
as the format specifier to make sure the sizes for both match.

src/journal/journald-console.c

index 5126c2160eb527fcd408485256f9eaa8878a2a3b..5fbcdb43c2ba63623d93a56494771c86974bb55e 100644 (file)
@@ -72,9 +72,9 @@ void server_forward_console(
         /* First: timestamp */
         if (prefix_timestamp()) {
                 assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
-                xsprintf(tbuf, "[%5"PRI_TIME".%06ld] ",
+                xsprintf(tbuf, "[%5"PRI_TIME".%06"PRI_NSEC"] ",
                          ts.tv_sec,
-                         ts.tv_nsec / 1000);
+                         (nsec_t)ts.tv_nsec / 1000);
                 IOVEC_SET_STRING(iovec[n++], tbuf);
         }