teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
Blob Blame History Raw
From d91fd10aaee61ae9281f96f0661d2a3564ed4274 Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date: Wed, 22 Mar 2017 21:34:32 +0100
Subject: [PATCH] journal/journald-console: fix format-specifier issue

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.

(cherry picked from commit b123d975ca50c5b44adaeb407cfd7da36c123b03)
---
 src/journal/journald-console.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c
index 5126c2160e..5fbcdb43c2 100644
--- a/src/journal/journald-console.c
+++ b/src/journal/journald-console.c
@@ -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);
         }