From 26112352a774737e1ce5580c93654a26c1e82b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 24 Oct 2022 22:25:29 +0200 Subject: New upstream version 1.1 --- tests/nanosleep.c | 93 +++---------------------------------------------------- 1 file changed, 5 insertions(+), 88 deletions(-) (limited to 'tests/nanosleep.c') diff --git a/tests/nanosleep.c b/tests/nanosleep.c index 5294c646..55d6fa65 100644 --- a/tests/nanosleep.c +++ b/tests/nanosleep.c @@ -23,16 +23,12 @@ #include #include "intprops.h" -#include "sig-handler.h" -#include "verify.h" -#include #include #include #include #include -#include #include #include @@ -61,7 +57,7 @@ nanosleep (const struct timespec *requested_delay, { /* Verify that time_t is large enough. */ - verify (TYPE_MAXIMUM (time_t) / 24 / 24 / 60 / 60); + static_assert (TYPE_MAXIMUM (time_t) / 24 / 24 / 60 / 60); const time_t limit = 24 * 24 * 60 * 60; time_t seconds = requested_delay->tv_sec; struct timespec intermediate; @@ -181,45 +177,9 @@ nanosleep (const struct timespec *requested_delay, } #else -/* Unix platforms lacking nanosleep. */ - -/* Some systems (MSDOS) don't have SIGCONT. - Using SIGTERM here turns the signal-handling code below - into a no-op on such systems. */ -# ifndef SIGCONT -# define SIGCONT SIGTERM -# endif - -static sig_atomic_t volatile suspended; - -/* Handle SIGCONT. */ - -static _GL_ASYNC_SAFE void -sighandler (int sig) -{ - suspended = 1; -} - -/* Suspend execution for at least *TS_DELAY seconds. */ - -static int -my_usleep (const struct timespec *ts_delay) -{ - struct timeval tv_delay; - tv_delay.tv_sec = ts_delay->tv_sec; - tv_delay.tv_usec = (ts_delay->tv_nsec + 999) / 1000; - if (tv_delay.tv_usec == 1000000) - { - if (tv_delay.tv_sec == TYPE_MAXIMUM (time_t)) - tv_delay.tv_usec = 1000000 - 1; /* close enough */ - else - { - tv_delay.tv_sec++; - tv_delay.tv_usec = 0; - } - } - return select (0, NULL, NULL, NULL, &tv_delay); -} +/* Other platforms lacking nanosleep. + It's not clear whether these are still practical porting targets. + For now, just fall back on pselect. */ /* Suspend execution for at least *REQUESTED_DELAY seconds. The *REMAINING_DELAY part isn't implemented yet. */ @@ -228,49 +188,6 @@ int nanosleep (const struct timespec *requested_delay, struct timespec *remaining_delay) { - static bool initialized; - - if (requested_delay->tv_nsec < 0 || BILLION <= requested_delay->tv_nsec) - { - errno = EINVAL; - return -1; - } - - /* set up sig handler */ - if (! initialized) - { - struct sigaction oldact; - - sigaction (SIGCONT, NULL, &oldact); - if (get_handler (&oldact) != SIG_IGN) - { - struct sigaction newact; - - newact.sa_handler = sighandler; - sigemptyset (&newact.sa_mask); - newact.sa_flags = 0; - sigaction (SIGCONT, &newact, NULL); - } - initialized = true; - } - - suspended = 0; - - if (my_usleep (requested_delay) == -1) - { - if (suspended) - { - /* Calculate time remaining. */ - /* FIXME: the code in sleep doesn't use this, so there's no - rush to implement it. */ - - errno = EINTR; - } - return -1; - } - - /* FIXME: Restore sig handler? */ - - return 0; + return pselect (0, NULL, NULL, NULL, requested_delay, NULL); } #endif -- cgit v1.2.3