diff options
author | Z. Liu <zhixu.liu@gmail.com> | 2024-08-28 16:12:43 +0800 |
---|---|---|
committer | Gerrit Pape <pape@smarden.org> | 2024-09-25 23:38:40 +0000 |
commit | b689a9838ee3908673975038d8b06d677179984f (patch) | |
tree | 2d26197d7d26397e8d4eeec109b112bab0022665 | |
parent | 0baa02d97aed285cb22a6292781874d8e63f3d6f (diff) | |
download | runit-b689a9838ee3908673975038d8b06d677179984f.tar.gz runit-b689a9838ee3908673975038d8b06d677179984f.tar.xz runit-b689a9838ee3908673975038d8b06d677179984f.zip |
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
-rw-r--r-- | src/sv.c | 14 |
1 files changed, 13 insertions, 1 deletions
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 <sys/types.h> #include <sys/stat.h> +#include <time.h> #include <unistd.h> #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); |