summaryrefslogtreecommitdiff
path: root/gl/lib/nanosleep.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2022-03-17 18:55:32 +0000
committerColin Watson <cjwatson@debian.org>2022-03-17 18:55:32 +0000
commit8a20bb7f39d2e3d90f2368a2a6b2a1ff8bc5968d (patch)
treee831769a198aa73f254242f0f75139640228cae8 /gl/lib/nanosleep.c
parent8729cc9a129888d81024f59510ac45a464a032c5 (diff)
parent968e4c27cfa5e48997eb69dfe0060bf8b2f295f4 (diff)
Import man-db_2.10.2.orig.tar.xz
Diffstat (limited to 'gl/lib/nanosleep.c')
-rw-r--r--gl/lib/nanosleep.c89
1 files changed, 4 insertions, 85 deletions
diff --git a/gl/lib/nanosleep.c b/gl/lib/nanosleep.c
index 5294c646..446794ed 100644
--- a/gl/lib/nanosleep.c
+++ b/gl/lib/nanosleep.c
@@ -23,7 +23,6 @@
#include <time.h>
#include "intprops.h"
-#include "sig-handler.h"
#include "verify.h"
#include <stdbool.h>
@@ -32,7 +31,6 @@
#include <sys/select.h>
#include <signal.h>
-#include <sys/time.h>
#include <errno.h>
#include <unistd.h>
@@ -181,45 +179,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 +190,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