From b689a9838ee3908673975038d8b06d677179984f Mon Sep 17 00:00:00 2001 From: "Z. Liu" Date: Wed, 28 Aug 2024 16:12:43 +0800 Subject: add sleep_microseconds to encapsulate (u|nano)sleep man 3 usleep: POSIX.1-2001 declares it obsolete, suggesting nanosleep(2) instead. Removed in POSIX.1-2008. we use a feature test macro to select usleep or naosleep, while debian's patch replace usleep with nanosleep. links of debian's patches is: https://salsa.debian.org/debian/runit/-/tree/master/debian/patches 0017-fix-replace-obsolete-usleep-with-nanosleep.patch --- src/sv.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/sv.c b/src/sv.c index 6ff9bc0..bccdf71 100644 --- a/src/sv.c +++ b/src/sv.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "str.h" #include "strerr.h" @@ -268,6 +269,17 @@ int control(char *a) { return(1); } +void sleep_microseconds(unsigned int microseconds) { +#if _POSIX_C_SOURCE >= 199309L + struct timespec sleeptime; + sleeptime.tv_sec = microseconds / 1000000; + sleeptime.tv_nsec = (microseconds % 1000000) * 1000L; + nanosleep(&sleeptime, NULL); +#else + usleep(microseconds); +#endif +} + int main(int argc, char **argv) { unsigned int i, done; char *x; @@ -387,7 +399,7 @@ int main(int argc, char **argv) { fatal("unable to change to original directory"); } if (done) break; - usleep(420000); + sleep_microseconds(420000); taia_now(&tnow); } return(rc > 99 ? 99 : rc); -- cgit 1.4.1