From bbc11135c296dbd7fbb6f4d40a0cdfd8ccf69c22 Mon Sep 17 00:00:00 2001 From: Mike Gilbert Date: Sun, 19 Dec 2021 19:39:37 -0500 Subject: [PATCH] basic: add a size check to format timex members properly As of glibc-2.34, the size of members in struct timex varies depending on the _TIME_BITS macro. Fixes: https://github.com/systemd/systemd/issues/21826 (cherry picked from commit 9a723ed6e80e3078969567f7cb551535d2fb00bd) --- meson.build | 1 + src/basic/format-util.h | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index acaa090fc0..02495d16c9 100644 --- a/meson.build +++ b/meson.build @@ -442,6 +442,7 @@ conf.set('SIZEOF_DEV_T', cc.sizeof('dev_t', prefix : '#include ')) conf.set('SIZEOF_INO_T', cc.sizeof('ino_t', prefix : '#include ')) conf.set('SIZEOF_TIME_T', cc.sizeof('time_t', prefix : '#include ')) conf.set('SIZEOF_RLIM_T', cc.sizeof('rlim_t', prefix : '#include ')) +conf.set('SIZEOF_TIMEX_MEMBER', cc.sizeof('((struct timex *)0)->freq', prefix : '#include ')) decl_headers = ''' #include diff --git a/src/basic/format-util.h b/src/basic/format-util.h index b7e18768e3..0272edaab8 100644 --- a/src/basic/format-util.h +++ b/src/basic/format-util.h @@ -26,10 +26,12 @@ assert_cc(sizeof(gid_t) == sizeof(uint32_t)); # error Unknown time_t size #endif -#if defined __x86_64__ && defined __ILP32__ +#if SIZEOF_TIMEX_MEMBER == 8 # define PRI_TIMEX PRIi64 -#else +#elif SIZEOF_TIMEX_MEMBER == 4 # define PRI_TIMEX "li" +#else +# error Unknown timex member size #endif #if SIZEOF_RLIM_T == 8 -- 2.25.1