mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 01:51:51 +00:00
timer: fix printf specifiers for __suseconds64_t
New internal glibc types __timeval64 [1] and __suseconds64_t [2] have been introduced as a solution for the Y2038 problem [3]. These 64-bit types are used across all architectures. However, this change causes the following build errors when cross-compiling on ARMv7 (armhf): criu/timer.c:49:17: error: format '%ld' expects argument of type 'long int', but argument 5 has type '__suseconds64_t' {aka 'long long int'} [-Werror=format=] 49 | pr_info("Restored %s timer to %" PRId64 ".%ld -> %" PRId64 ".%ld\n", n, | ^~~~~~~~~~~~~~~~~~~~~~~~ 50 | (int64_t)val->it_value.tv_sec, val->it_value.tv_usec, | ~~~~~~~~~~~~~~~~~~~~~ | | | __suseconds64_t {aka long long int} criu/timer.c:49:17: error: format '%ld' expects argument of type 'long int', but argument 7 has type '__suseconds64_t' {aka 'long long int'} [-Werror=format=] 49 | pr_info("Restored %s timer to %" PRId64 ".%ld -> %" PRId64 ".%ld\n", n, | ^~~~~~~~~~~~~~~~~~~~~~~~ 50 | (int64_t)val->it_value.tv_sec, val->it_value.tv_usec, 51 | (int64_t)val->it_interval.tv_sec, val->it_interval.tv_usec); | ~~~~~~~~~~~~~~~~~~~~~~~~ | | | __suseconds64_t {aka long long int} ns.c:234:48: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'time_t' {aka 'long long int'} [-Werror=format=] 234 | len = snprintf(buf, sizeof(buf), "%d %ld 0", clk_id, offset); | ~~^ ~~~~~~ | | | | long int time_t {aka long long int} | %lld msg.c:58:41: error: format '%ld' expects argument of type 'long int', but argument 3 has type '__suseconds64_t' {aka 'long long int'} [-Werror=format=] 58 | off += sprintf(buf + off, ".%.3ld: ", tv.tv_usec / 1000); | ~~~~^ ~~~~~~~~~~~~~~~~~ | | | | long int __suseconds64_t {aka long long int} | %.3lld ../lib/zdtmtst.h:137:26: error: format '%ld' expects argument of type 'long int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 137 | test_msg("ERR: %s:%d: " format " (errno = %d (%s))\n", __FILE__, __LINE__, ##arg, errno, \ | ^~~~~~~~~~~~~~ pthread_timers_h.c:72:17: note: in expansion of macro 'pr_perror' 72 | pr_perror("wrong interval: %ld:%ld", itimerspec.it_interval.tv_sec, itimerspec.it_interval.tv_nsec); | ^~~~~~~~~ vdso00.c:22:32: error: format '%li' expects argument of type 'long int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 22 | test_msg("%d time: %10li\n", getpid(), tv.tv_sec); | ~~~~^ ~~~~~~~~~ | | | | long int __time64_t {aka long long int} | %10lli vdso00.c:29:32: error: format '%li' expects argument of type 'long int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 29 | test_msg("%d time: %10li\n", getpid(), tv.tv_sec); | ~~~~^ ~~~~~~~~~ | | | | long int __time64_t {aka long long int} | %10lli vdso01.c:357:42: error: format '%li' expects argument of type 'long int', but argument 2 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 357 | test_msg("gettimeofday: tv_sec %li vdso_gettimeofday: tv_sec %li\n", tv1.tv_sec, tv2.tv_sec); | ~~^ ~~~~~~~~~~ | | | | long int __time64_t {aka long long int} | %lli vdso01.c:357:72: error: format '%li' expects argument of type 'long int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 357 | test_msg("gettimeofday: tv_sec %li vdso_gettimeofday: tv_sec %li\n", tv1.tv_sec, tv2.tv_sec); | ~~^ ~~~~~~~~~~ | | | | long int __time64_t {aka long long int} | vdso01.c:328:43: error: format '%li' expects argument of type 'long int', but argument 2 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 328 | test_msg("clock_gettime: tv_sec %li vdso_clock_gettime: tv_sec %li\n", ts1.tv_sec, ts2.tv_sec); | ~~^ ~~~~~~~~~~ | | | | long int __time64_t {aka long long int} | %lli vdso01.c:328:74: error: format '%li' expects argument of type 'long int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 328 | test_msg("clock_gettime: tv_sec %li vdso_clock_gettime: tv_sec %li\n", ts1.tv_sec, ts2.tv_sec); | ~~^ ~~~~~~~~~~ | | | | long int __time64_t {aka long long int} | ../lib/zdtmtst.h:144:26: error: format '%ld' expects argument of type 'long int', but argument 4 has type 'time_t' {aka 'long long int'} [-Werror=format=] 144 | test_msg("FAIL: %s:%d: " format " (errno = %d (%s))\n", __FILE__, __LINE__, ##arg, errno, \ | ^~~~~~~~~~~~~~~ mtime_mmap.c:80:17: note: in expansion of macro 'fail' 80 | fail("mtime %ld wasn't updated on mmapped %s file", mtime_new, filename); | ^~~~ ../lib/zdtmtst.h:144:26: error: format '%ld' expects argument of type 'long int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Werror=format=] 144 | test_msg("FAIL: %s:%d: " format " (errno = %d (%s))\n", __FILE__, __LINE__, ##arg, errno, \ | ^~~~~~~~~~~~~~~ mtime_mmap.c:101:17: note: in expansion of macro 'fail' 101 | fail("After migration, mtime changed to %ld", fst.st_mtime); | ^~~~ [1] https://sourceware.org/git/?p=glibc.git;h=504c98717062cb9bcbd4b3e59e932d04331ddca5 [2] https://sourceware.org/git/?p=glibc.git;h=3fced064f23562ec24f8312ffbc14950993969e6 [3] https://en.wikipedia.org/wiki/Year_2038_problem Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
parent
a045c874cb
commit
551cd92447
@ -46,9 +46,9 @@ static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val)
|
||||
return -1;
|
||||
}
|
||||
|
||||
pr_info("Restored %s timer to %" PRId64 ".%ld -> %" PRId64 ".%ld\n", n,
|
||||
(int64_t)val->it_value.tv_sec, val->it_value.tv_usec,
|
||||
(int64_t)val->it_interval.tv_sec, val->it_interval.tv_usec);
|
||||
pr_info("Restored %s timer to %" PRId64 ".%" PRId64 " -> %" PRId64 ".%" PRId64 "\n", n,
|
||||
(int64_t)val->it_value.tv_sec, (int64_t)val->it_value.tv_usec,
|
||||
(int64_t)val->it_interval.tv_sec, (int64_t)val->it_interval.tv_usec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <stdarg.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@ -55,7 +56,7 @@ void test_msg(const char *format, ...)
|
||||
off += strftime(buf, sizeof(buf), "%H:%M:%S", tm);
|
||||
}
|
||||
|
||||
off += sprintf(buf + off, ".%.3ld: ", tv.tv_usec / 1000);
|
||||
off += sprintf(buf + off, ".%.3" PRId64 ": ", (int64_t)(tv.tv_usec / 1000));
|
||||
off += sprintf(buf + off, "%5d: ", getpid());
|
||||
|
||||
skip:
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
#include <grp.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@ -231,7 +232,7 @@ static inline int _settime(clockid_t clk_id, time_t offset)
|
||||
if (clk_id == CLOCK_MONOTONIC_COARSE || clk_id == CLOCK_MONOTONIC_RAW)
|
||||
clk_id = CLOCK_MONOTONIC;
|
||||
|
||||
len = snprintf(buf, sizeof(buf), "%d %ld 0", clk_id, offset);
|
||||
len = snprintf(buf, sizeof(buf), "%d %" PRId64 " 0", clk_id, (int64_t)offset);
|
||||
|
||||
fd = open("/proc/self/timens_offsets", O_WRONLY);
|
||||
if (fd < 0) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@ -77,7 +78,7 @@ int main(int argc, char **argv)
|
||||
mtime_new = fst.st_mtime;
|
||||
/* time of last modification */
|
||||
if (mtime_new <= mtime_old) {
|
||||
fail("mtime %ld wasn't updated on mmapped %s file", mtime_new, filename);
|
||||
fail("mtime %" PRId64 " wasn't updated on mmapped %s file", (int64_t)mtime_new, filename);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
@ -98,7 +99,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* time of last modification */
|
||||
if (fst.st_mtime != mtime_new) {
|
||||
fail("After migration, mtime changed to %ld", fst.st_mtime);
|
||||
fail("After migration, mtime changed to %" PRId64, (int64_t)fst.st_mtime);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
@ -69,7 +70,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (itimerspec.it_interval.tv_nsec != TEST_INTERVAL_NSEC || itimerspec.it_interval.tv_sec) {
|
||||
pr_perror("wrong interval: %ld:%ld", itimerspec.it_interval.tv_sec, itimerspec.it_interval.tv_nsec);
|
||||
pr_perror("wrong interval: %" PRId64 ":%" PRId64,
|
||||
(int64_t)itimerspec.it_interval.tv_sec, (int64_t)itimerspec.it_interval.tv_nsec);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
@ -19,14 +19,14 @@ int main(int argc, char *argv[])
|
||||
test_msg("%s pid %d\n", argv[0], getpid());
|
||||
|
||||
gettimeofday(&tv, &tz);
|
||||
test_msg("%d time: %10li\n", getpid(), tv.tv_sec);
|
||||
test_msg("%d time: %10" PRId64 "\n", getpid(), (int64_t)tv.tv_sec);
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
/* this call will fail if vDSO is corrupted */
|
||||
gettimeofday(&tv, &tz);
|
||||
test_msg("%d time: %10li\n", getpid(), tv.tv_sec);
|
||||
test_msg("%d time: %10" PRId64 "\n", getpid(), (int64_t)tv.tv_sec);
|
||||
|
||||
pass();
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
@ -324,7 +325,8 @@ static int vdso_clock_gettime_handler(void *func)
|
||||
clock_gettime(CLOCK_REALTIME, &ts1);
|
||||
vdso_clock_gettime(CLOCK_REALTIME, &ts2);
|
||||
|
||||
test_msg("clock_gettime: tv_sec %li vdso_clock_gettime: tv_sec %li\n", ts1.tv_sec, ts2.tv_sec);
|
||||
test_msg("clock_gettime: tv_sec %" PRId64 " vdso_clock_gettime: tv_sec %" PRId64 "\n",
|
||||
(int64_t)ts1.tv_sec, (int64_t)ts2.tv_sec);
|
||||
|
||||
if (labs(ts1.tv_sec - ts2.tv_sec) > TIME_DELTA_SEC) {
|
||||
pr_perror("Delta is too big");
|
||||
@ -354,7 +356,8 @@ static int vdso_gettimeofday_handler(void *func)
|
||||
gettimeofday(&tv1, &tz);
|
||||
vdso_gettimeofday(&tv2, &tz);
|
||||
|
||||
test_msg("gettimeofday: tv_sec %li vdso_gettimeofday: tv_sec %li\n", tv1.tv_sec, tv2.tv_sec);
|
||||
test_msg("gettimeofday: tv_sec %" PRId64 " vdso_gettimeofday: tv_sec %" PRId64 "\n",
|
||||
(int64_t)tv1.tv_sec, (int64_t)tv2.tv_sec);
|
||||
|
||||
if (labs(tv1.tv_sec - tv2.tv_sec) > TIME_DELTA_SEC) {
|
||||
pr_perror("Delta is too big");
|
||||
|
Loading…
x
Reference in New Issue
Block a user