projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
.
[gnulib.git]
/
lib
/
nanosleep.c
diff --git
a/lib/nanosleep.c
b/lib/nanosleep.c
index
b51f648
..
42f179c
100644
(file)
--- a/
lib/nanosleep.c
+++ b/
lib/nanosleep.c
@@
-22,43
+22,43
@@
#include <sys/types.h>
#include <signal.h>
#include <sys/types.h>
#include <signal.h>
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <time.h>
/* FIXME: is including both like this kosher? */
#include <sys/time.h>
#include <time.h>
/* FIXME: is including both like this kosher? */
#include <sys/time.h>
-static interrupted;
+static int suspended;
+int first_call = 1;
/* Handle SIGCONT. */
static void
sighandler (int sig)
{
/* Handle SIGCONT. */
static void
sighandler (int sig)
{
-#ifdef SA_INTERRUPT
- struct sigaction sigact;
-
- sigact.sa_handler = SIG_DFL;
- sigemptyset (&sigact.sa_mask);
- sigact.sa_flags = 0;
- sigaction (sig, &sigact, NULL);
-#else
- signal (sig, SIG_DFL);
-#endif
-
suspended = 1;
suspended = 1;
- kill (getpid (), sig);
}
}
-/*
Sleep for USEC microseconds.
*/
+/*
FIXME: comment
*/
static void
static void
-usleep (const struct timespec *ts_delay)
+
my_
usleep (const struct timespec *ts_delay)
{
struct timeval tv_delay;
tv_delay.tv_sec = ts_delay->tv_sec;
{
struct timeval tv_delay;
tv_delay.tv_sec = ts_delay->tv_sec;
- tv_delay.tv_usec =
1000 * ts_delay->tv_nsec
;
- select (0, (void *) 0, (void *) 0, (void *) 0, tv_delay);
+ tv_delay.tv_usec =
ts_delay->tv_nsec / 1000
;
+ select (0, (void *) 0, (void *) 0, (void *) 0,
&
tv_delay);
}
}
+/* FIXME: comment */
+
int
nanosleep (const struct timespec *requested_delay,
struct timespec *remaining_delay)
int
nanosleep (const struct timespec *requested_delay,
struct timespec *remaining_delay)
@@
-67,32
+67,38
@@
nanosleep (const struct timespec *requested_delay,
struct sigaction oldact, newact;
#endif
struct sigaction oldact, newact;
#endif
-
interrupt
ed = 0;
+
suspend
ed = 0;
- /* set up sig handler -- but maybe only do this the first time? */
+ /* set up sig handler */
+ if (first_call)
+ {
#ifdef SA_INTERRUPT
#ifdef SA_INTERRUPT
- newact.sa_handler = sighandler;
- sigemptyset (&newact.sa_mask);
- newact.sa_flags = 0;
+
newact.sa_handler = sighandler;
+
sigemptyset (&newact.sa_mask);
+
newact.sa_flags = 0;
- sigaction (SIGCONT, NULL, &oldact);
- if (oldact.sa_handler != SIG_IGN)
- sigaction (SIGCONT, &newact, NULL);
+
sigaction (SIGCONT, NULL, &oldact);
+
if (oldact.sa_handler != SIG_IGN)
+
sigaction (SIGCONT, &newact, NULL);
#else
#else
- if (signal (SIGCONT, SIG_IGN) != SIG_IGN)
- signal (SIGCONT, sighandler);
+
if (signal (SIGCONT, SIG_IGN) != SIG_IGN)
+
signal (SIGCONT, sighandler);
#endif
#endif
+ first_call = 0;
+ }
- usleep (requested_delay);
+
my_
usleep (requested_delay);
- if (
interrupt
ed)
+ if (
suspend
ed)
{
/* Calculate time remaining. */
/* FIXME: the code in sleep doesn't use this, so there's no
rush to implement it. */
{
/* Calculate time remaining. */
/* FIXME: the code in sleep doesn't use this, so there's no
rush to implement it. */
+
+ errno = EINTR;
}
/* FIXME: Restore sig handler? */
}
/* FIXME: Restore sig handler? */
- return
interrupt
ed;
+ return
suspend
ed;
}
}