summaryrefslogtreecommitdiff
path: root/tests/nanosleep.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2022-10-24 22:26:08 +0200
committerJörg Frings-Fürst <debian@jff.email>2022-10-24 22:26:08 +0200
commite97e0882ffc87a91e7818137196f1b74134566df (patch)
tree285662381eaa0514f988142bff0c8a9685c84dc0 /tests/nanosleep.c
parentcc0876a2fa9e703b1064992ab535f3eed57e9c71 (diff)
parentcb4186bef1b44691db4221406d001a8d40c65b4b (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'tests/nanosleep.c')
-rw-r--r--tests/nanosleep.c93
1 files changed, 5 insertions, 88 deletions
diff --git a/tests/nanosleep.c b/tests/nanosleep.c
index 5294c64..55d6fa6 100644
--- a/tests/nanosleep.c
+++ b/tests/nanosleep.c
@@ -23,16 +23,12 @@
#include <time.h>
#include "intprops.h"
-#include "sig-handler.h"
-#include "verify.h"
-#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/select.h>
#include <signal.h>
-#include <sys/time.h>
#include <errno.h>
#include <unistd.h>
@@ -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