From b123d975ca50c5b44adaeb407cfd7da36c123b03 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Wed, 22 Mar 2017 21:34:32 +0100 Subject: [PATCH 1/4] 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. --- 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); } From cc9211b030c1fa7dd8d0e14df1de3e2aba32e50c Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Wed, 22 Mar 2017 21:40:51 +0100 Subject: [PATCH 2/4] udev/udevadm-monitor: 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. --- src/udev/udevadm-monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index f631834341..94a59186ed 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -41,9 +41,9 @@ static void print_device(struct udev_device *device, const char *source, int pro struct timespec ts; assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); - printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n", + printf("%-6s[%"PRI_TIME".%06"PRI_NSEC"] %-8s %s (%s)\n", source, - ts.tv_sec, ts.tv_nsec/1000, + ts.tv_sec, (nsec_t)ts.tv_nsec/1000, udev_device_get_action(device), udev_device_get_devpath(device), udev_device_get_subsystem(device)); From 3bd7ef833caae7431a9c50450ce7b303234d45eb Mon Sep 17 00:00:00 2001 From: Matija Skala Date: Fri, 19 May 2017 14:36:12 +0200 Subject: [PATCH 3/4] timesync/timesyncd-manager: fix format-specifier issues timex::time::tv_usec and timex::freq 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 li as a format specifier will trigger a format error. Thus, introduce a new format specifier PRI_TIMEX which is defined as PRIi64 on x32 and li everywhere else. --- src/basic/format-util.h | 6 ++++++ src/timesync/timesyncd-manager.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/basic/format-util.h b/src/basic/format-util.h index 39a185f59b..ae42a8f89e 100644 --- a/src/basic/format-util.h +++ b/src/basic/format-util.h @@ -54,6 +54,12 @@ # error Unknown time_t size #endif +#if defined __x86_64__ && defined __ILP32__ +# define PRI_TIMEX PRIi64 +#else +# define PRI_TIMEX "li" +#endif + #if SIZEOF_RLIM_T == 8 # define RLIM_FMT "%" PRIu64 #elif SIZEOF_RLIM_T == 4 diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 6a6c1577c6..11c495e291 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -379,9 +379,9 @@ static int manager_adjust_clock(Manager *m, double offset, int leap_sec) { log_debug(" status : %04i %s\n" " time now : %li.%03"PRI_USEC"\n" - " constant : %li\n" + " constant : %"PRI_TIMEX"\n" " offset : %+.3f sec\n" - " freq offset : %+li (%i ppm)\n", + " freq offset : %+"PRI_TIMEX" (%i ppm)\n", tmx.status, tmx.status & STA_UNSYNC ? "unsync" : "sync", tmx.time.tv_sec, tmx.time.tv_usec / NSEC_PER_MSEC, tmx.constant, From 0060bb8f5bbad433bc29405cc76b955d3125d8e9 Mon Sep 17 00:00:00 2001 From: Matija Skala Date: Fri, 19 May 2017 14:36:40 +0200 Subject: [PATCH 4/4] timesync/timesyncd-manager: fix format-specifier issue timex::time::tv_sec 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 li as a format specifier will trigger a format error. Thus, better use PRI_TIME instead of li which is actually the right format specifier to use for time_t. --- src/timesync/timesyncd-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 11c495e291..ae8514550a 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -378,7 +378,7 @@ static int manager_adjust_clock(Manager *m, double offset, int leap_sec) { m->drift_ppm = tmx.freq / 65536; log_debug(" status : %04i %s\n" - " time now : %li.%03"PRI_USEC"\n" + " time now : %"PRI_TIME".%03"PRI_USEC"\n" " constant : %"PRI_TIMEX"\n" " offset : %+.3f sec\n" " freq offset : %+"PRI_TIMEX" (%i ppm)\n",