hostapd: backport usleep patch
[openwrt/openwrt.git] / package / network / services / hostapd / patches / 800-usleep.patch
1 From 39042d7f7c4997af55474ebe4513c81f00732837 Mon Sep 17 00:00:00 2001
2 From: Rosen Penev <rosenp@gmail.com>
3 Date: Sat, 24 Aug 2019 15:01:16 -0700
4 Subject: os_sleep: Use nanosleep for POSIX versions 2008 and higher
5
6 uClibc-ng optionally disabled deprecated POSIX functions like usleep,
7 causing compilation failures. This switches to nanosleep while retaining
8 support for older libcs that do not support nanosleep.
9
10 Signed-off-by: Rosen Penev <rosenp@gmail.com>
11 ---
12 src/utils/os_internal.c | 6 ++++++
13 src/utils/os_unix.c | 6 ++++++
14 2 files changed, 12 insertions(+)
15
16 --- a/src/utils/os_internal.c
17 +++ b/src/utils/os_internal.c
18 @@ -25,10 +25,16 @@
19
20 void os_sleep(os_time_t sec, os_time_t usec)
21 {
22 +#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
23 + const struct timespec req = { sec, usec * 1000 };
24 +
25 + nanosleep(&req, NULL);
26 +#else
27 if (sec)
28 sleep(sec);
29 if (usec)
30 usleep(usec);
31 +#endif
32 }
33
34
35 --- a/src/utils/os_unix.c
36 +++ b/src/utils/os_unix.c
37 @@ -50,10 +50,16 @@ struct os_alloc_trace {
38
39 void os_sleep(os_time_t sec, os_time_t usec)
40 {
41 +#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
42 + const struct timespec req = { sec, usec * 1000 };
43 +
44 + nanosleep(&req, NULL);
45 +#else
46 if (sec)
47 sleep(sec);
48 if (usec)
49 usleep(usec);
50 +#endif
51 }
52
53