From 8f7f73e4af916bf1bc6a0cb72be35b7061b297df Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 30 Mar 2023 17:46:25 +0500 Subject: [PATCH] Sleep using nanosleep() instead of select(). This is a safer way to sleep due to select's not-portable interaction with signals. Based on https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=a948e49e2ef11815be0b211723bfc5b53b7f75a8 from the PostgreSQL project. --- src/common/time.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common/time.c b/src/common/time.c index da634f857..d9b7d5117 100644 --- a/src/common/time.c +++ b/src/common/time.c @@ -28,7 +28,7 @@ timeMSec(void) /**********************************************************************************************************************************/ FN_EXTERN void -sleepMSec(TimeMSec sleepMSec) +sleepMSec(const TimeMSec sleepMSec) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(UINT64, sleepMSec); @@ -36,10 +36,13 @@ sleepMSec(TimeMSec sleepMSec) if (sleepMSec > 0) { - struct timeval delay; - delay.tv_sec = (time_t)(sleepMSec / MSEC_PER_SEC); - delay.tv_usec = (suseconds_t)(sleepMSec % MSEC_PER_SEC * 1000); - select(0, NULL, NULL, NULL, &delay); + const struct timespec delay = + { + .tv_sec = (time_t)(sleepMSec / MSEC_PER_SEC), + .tv_nsec = (long)(sleepMSec % MSEC_PER_SEC * 1000000), + }; + + nanosleep(&delay, NULL); } FUNCTION_TEST_RETURN_VOID();