diff options
Diffstat (limited to 'libc/unistd/sleep.c')
-rw-r--r-- | libc/unistd/sleep.c | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c index e7152c46b..4d55d843d 100644 --- a/libc/unistd/sleep.c +++ b/libc/unistd/sleep.c @@ -66,10 +66,9 @@ unsigned int sleep (unsigned int seconds) /* Linux will wake up the system call, nanosleep, when SIGCHLD arrives even if SIGCHLD is ignored. We have to deal with it in libc. We block SIGCHLD first. */ - if (__sigemptyset (&set) < 0 - || __sigaddset (&set, SIGCHLD) < 0 - || sigprocmask (SIG_BLOCK, &set, &oset)) - return -1; + __sigemptyset (&set); + __sigaddset (&set, SIGCHLD); + sigprocmask (SIG_BLOCK, &set, &oset); /* can't fail */ /* If SIGCHLD is already blocked, we don't have to do anything. */ if (!__sigismember (&oset, SIGCHLD)) @@ -77,18 +76,10 @@ unsigned int sleep (unsigned int seconds) int saved_errno; struct sigaction oact; - if (__sigemptyset (&set) < 0 || __sigaddset (&set, SIGCHLD) < 0) - return -1; + __sigemptyset (&set); + __sigaddset (&set, SIGCHLD); - /* We get the signal handler for SIGCHLD. */ - if (sigaction (SIGCHLD, (struct sigaction *) NULL, &oact) < 0) - { - saved_errno = errno; - /* Restore the original signal mask. */ - (void) sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL); - __set_errno (saved_errno); - return -1; - } + sigaction (SIGCHLD, NULL, &oact); /* never fails */ if (oact.sa_handler == SIG_IGN) { @@ -97,13 +88,13 @@ unsigned int sleep (unsigned int seconds) saved_errno = errno; /* Restore the original signal mask. */ - (void) sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL); + sigprocmask (SIG_SETMASK, &oset, NULL); __set_errno (saved_errno); } else { /* We should unblock SIGCHLD. Restore the original signal mask. */ - (void) sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL); + sigprocmask (SIG_SETMASK, &oset, NULL); result = nanosleep (&ts, &ts); } } @@ -136,29 +127,27 @@ unsigned int sleep (unsigned int seconds) return 0; /* block SIGALRM */ - if (__sigemptyset (&set) < 0 - || __sigaddset (&set, SIGALRM) < 0 - || sigprocmask (SIG_BLOCK, &set, &oset)) - return seconds; + __sigemptyset (&set); + __sigaddset (&set, SIGALRM); + sigprocmask (SIG_BLOCK, &set, &oset); /* can't fail */ act.sa_handler = sleep_alarm_handler; act.sa_flags = 0; act.sa_mask = oset; - if (sigaction(SIGALRM, &act, &oact) < 0) - return seconds; + sigaction(SIGALRM, &act, &oact); /* never fails */ before = time(NULL); remaining = alarm(seconds); if (remaining && remaining > seconds) { /* restore user's alarm */ - (void) sigaction(SIGALRM, &oact, (struct sigaction *) NULL); + sigaction(SIGALRM, &oact, NULL); alarm(remaining); /* restore old alarm */ sigsuspend(&oset); after = time(NULL); } else { sigsuspend (&oset); after = time(NULL); - (void) sigaction (SIGALRM, &oact, NULL); + sigaction (SIGALRM, &oact, NULL); } result = after - before; alarm(remaining > result ? remaining - result : 0); |