summaryrefslogtreecommitdiff
path: root/libc/unistd/sleep.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 21:16:46 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 21:16:46 +0000
commitb0a365f74a0ac43fcbd53738844e577b2d9ec391 (patch)
tree262cc91ab047162f77df33a48891499434b56ca0 /libc/unistd/sleep.c
parentfbb32ad9b6a4b6cffea1c5b4292b18c72cdadaf6 (diff)
hostid: improve extremely unreadable parts
*: remove checks of sigaction and sigprocmask results in cases where they clearly can't fail: sigaction(known_good_sig) sigprocmask(known_good_how) text data bss dec hex filename - 393 4 0 397 18d libc/pwd_grp/lckpwdf.o + 382 4 0 386 182 libc/pwd_grp/lckpwdf.o - 56 0 0 56 38 libc/signal/sigblock.o + 44 0 0 44 2c libc/signal/sigblock.o - 211 0 0 211 d3 libc/signal/sigset.o + 202 0 0 202 ca libc/signal/sigset.o - 56 0 0 56 38 libc/signal/sigsetmask.o + 44 0 0 44 2c libc/signal/sigsetmask.o - 309 0 0 309 135 libc/unistd/sleep.o + 256 0 0 256 100 libc/unistd/sleep.o
Diffstat (limited to 'libc/unistd/sleep.c')
-rw-r--r--libc/unistd/sleep.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/libc/unistd/sleep.c b/libc/unistd/sleep.c
index 8cac306ce..4d55d843d 100644
--- a/libc/unistd/sleep.c
+++ b/libc/unistd/sleep.c
@@ -68,8 +68,7 @@ unsigned int sleep (unsigned int seconds)
in libc. We block SIGCHLD first. */
__sigemptyset (&set);
__sigaddset (&set, SIGCHLD);
- if (sigprocmask (SIG_BLOCK, &set, &oset))
- return -1;
+ sigprocmask (SIG_BLOCK, &set, &oset); /* can't fail */
/* If SIGCHLD is already blocked, we don't have to do anything. */
if (!__sigismember (&oset, SIGCHLD))
@@ -80,15 +79,7 @@ unsigned int sleep (unsigned int seconds)
__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);
}
}
@@ -138,27 +129,25 @@ unsigned int sleep (unsigned int seconds)
/* block SIGALRM */
__sigemptyset (&set);
__sigaddset (&set, SIGALRM);
- if (sigprocmask (SIG_BLOCK, &set, &oset))
- return seconds;
+ 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);