diff options
author | Jim Meyering <jim@meyering.net> | 1999-12-26 09:40:16 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-12-26 09:40:16 +0000 |
commit | 2dc33d421eaa01c42a337f5f0dedc62db17f3874 (patch) | |
tree | c62c4f24db70704809d5c7776b7cd348e66e4154 /lib | |
parent | 0ac76a646bf5c84126310b52742176aaa5d3e591 (diff) | |
download | coreutils-2dc33d421eaa01c42a337f5f0dedc62db17f3874.tar.xz |
*** empty log message ***
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nanosleep.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/nanosleep.c b/lib/nanosleep.c index b833c01f4..b51f648c7 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -18,8 +18,9 @@ /* written by Jim Meyering */ #include <config.h> - +#include <stdio.h> #include <sys/types.h> +#include <signal.h> #include <time.h> /* FIXME: is including both like this kosher? */ @@ -27,6 +28,26 @@ static interrupted; +/* 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; + kill (getpid (), sig); +} + /* Sleep for USEC microseconds. */ static void @@ -42,10 +63,25 @@ int nanosleep (const struct timespec *requested_delay, struct timespec *remaining_delay) { +#ifdef SA_INTERRUPT + struct sigaction oldact, newact; +#endif + interrupted = 0; /* set up sig handler -- but maybe only do this the first time? */ - /* FIXME */ +#ifdef SA_INTERRUPT + 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); +#else + if (signal (SIGCONT, SIG_IGN) != SIG_IGN) + signal (SIGCONT, sighandler); +#endif usleep (requested_delay); |