1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

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.
This commit is contained in:
David Steele 2023-03-30 17:46:25 +05:00
parent 2cfbee903a
commit 8f7f73e4af

View File

@ -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();