Merge pull request #17303 from CarlosDerSeher/feature_bt_agent
[feed/packages.git] / net / atlas-probe / patches / 002-Avoid-problems-with-64-bit-time_t.patch
1 From 46da4c4e090e0412cee0777f1e8b219964781da7 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cotequeiroz@gmail.com>
3 Date: Fri, 8 Oct 2021 14:39:52 -0300
4 Subject: [PATCH] Avoid problems with 64-bit time_t
5
6 The clock_gettime() calls are being handled by calling
7 syscall(__NR_clock_gettime, ...), which is not portable between systems
8 using 32-bit and 64-bit time_t. This is being done to avoid having to
9 link agains librt.
10
11 So, use the standard function, and add a test to see if we can compile
12 a test without the library, including it otherwise.
13
14 Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
15 ---
16 Makefile.flags | 6 ++++++
17 coreutils/date.c | 6 ++----
18 libbb/time.c | 2 +-
19 3 files changed, 9 insertions(+), 5 deletions(-)
20
21 --- a/Makefile.flags
22 +++ b/Makefile.flags
23 @@ -124,6 +124,12 @@ CFLAGS += --sysroot=$(CONFIG_SYSROOT)
24 export SYSROOT=$(CONFIG_SYSROOT)
25 endif
26
27 +# glibc versions before 2.17 need to link with -rt to use clock_gettime
28 +RT_NEEDED := $(shell echo 'int main(void){struct timespec tp; return clock_gettime(CLOCK_MONOTONIC, &tp);}' >rttest.c; $(CC) $(CFLAGS) -include time.h -o /dev/null rttest.c >/dev/null 2>&1 || echo "y"; rm rttest.c)
29 +ifeq ($(RT_NEEDED),y)
30 +LDLIBS += rt
31 +endif
32 +
33 # Android has no separate crypt library
34 # gcc-4.2.1 fails if we try to feed C source on stdin:
35 # echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
36 --- a/coreutils/date.c
37 +++ b/coreutils/date.c
38 @@ -37,7 +37,7 @@
39 //config:config FEATURE_DATE_NANO
40 //config: bool "Support %[num]N nanosecond format specifier"
41 //config: default n
42 -//config: depends on DATE # syscall(__NR_clock_gettime)
43 +//config: depends on DATE # clock_gettime()
44 //config: select PLATFORM_LINUX
45 //config: help
46 //config: Support %[num]N format specifier. Adds ~250 bytes of code.
47 @@ -265,9 +265,7 @@ int date_main(int argc UNUSED_PARAM, cha
48 #endif
49 } else {
50 #if ENABLE_FEATURE_DATE_NANO
51 - /* libc has incredibly messy way of doing this,
52 - * typically requiring -lrt. We just skip all this mess */
53 - syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
54 + clock_gettime(CLOCK_REALTIME, &ts);
55 #else
56 time(&ts.tv_sec);
57 #endif
58 --- a/libbb/time.c
59 +++ b/libbb/time.c
60 @@ -243,7 +243,7 @@ char* FAST_FUNC strftime_YYYYMMDDHHMMSS(
61 * typically requiring -lrt. We just skip all this mess */
62 static void get_mono(struct timespec *ts)
63 {
64 - if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts))
65 + if (clock_gettime(CLOCK_MONOTONIC, ts))
66 bb_error_msg_and_die("clock_gettime(MONOTONIC) failed");
67 }
68 unsigned long long FAST_FUNC monotonic_ns(void)