From aecf3f55cefed379927638d6fb3f867fcb1f3571 Mon Sep 17 00:00:00 2001 From: Alan Zhao Date: Wed, 15 May 2024 15:14:52 -0700 Subject: [PATCH] Use nanosleep(2) instead of usleep(3) usleep(3) was declared obsolete in POSIX.1-2001 and removed in POSIX.1-2008 and nanosleep(2) was recommended to be used instead. --- code/autoupdater/autoupdater.c | 5 ++++- code/sys/sys_unix.c | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/code/autoupdater/autoupdater.c b/code/autoupdater/autoupdater.c index 4a052027..e013a1f4 100644 --- a/code/autoupdater/autoupdater.c +++ b/code/autoupdater/autoupdater.c @@ -933,10 +933,13 @@ static void waitToApplyUpdates(void) OS forcibly closes the pipe), we will unblock. Then we can loop on kill() until the process is truly gone. */ int x = 0; + struct timespec req; + req.tv_sec = 0; + req.tv_nsec = 100000000; read(3, &x, sizeof (x)); info("Pipe has closed, waiting for process to fully go away now."); while (kill(options.waitforprocess, 0) == 0) { - usleep(100000); + nanosleep(&req, NULL); } #endif } diff --git a/code/sys/sys_unix.c b/code/sys/sys_unix.c index 66b6fa17..db29e8f0 100644 --- a/code/sys/sys_unix.c +++ b/code/sys/sys_unix.c @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include qboolean stdinIsATTY; @@ -548,11 +549,15 @@ void Sys_Sleep( int msec ) } else { + struct timespec req; + // With nothing to select() on, we can't wait indefinitely if( msec < 0 ) msec = 10; - usleep( msec * 1000 ); + req.tv_sec = msec/1000; + req.tv_nsec = (msec%1000)*1000000; + nanosleep(&req, NULL); } }