From a4ddecaa6a99210f9bc6910c078a3a1cf1667c30 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 7 Feb 2014 21:08:57 +0000 Subject: Don't nest too much --- sinit.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sinit.c b/sinit.c index bfa655f..a3c2db2 100644 --- a/sinit.c +++ b/sinit.c @@ -56,9 +56,11 @@ main(void) if (sigemptyset(&sigset) < 0) eprintf("sinit: sigemptyset:"); + for (i = 0; i < LEN(dispatchsig); i++) if (sigaddset(&sigset, dispatchsig[i].sig) < 0) eprintf("sinit: sigaddset:"); + if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) eprintf("sinit: sigprocmask:"); @@ -74,17 +76,17 @@ main(void) ret = select(sigfd + 1, &rfds, NULL, NULL, NULL); if (ret < 0) eprintf("sinit: select:"); - if (ret > 0) { - if (FD_ISSET(sigfd, &rfds)) { - n = read(sigfd, &siginfo, sizeof(siginfo)); - if (n < 0) - eprintf("sinit: read:"); - if (n != sizeof(siginfo)) - continue; - for (i = 0; i < LEN(dispatchsig); i++) - if (dispatchsig[i].sig == siginfo.ssi_signo) - dispatchsig[i].func(); - } + if (ret == 0) + continue; + if (FD_ISSET(sigfd, &rfds)) { + n = read(sigfd, &siginfo, sizeof(siginfo)); + if (n < 0) + eprintf("sinit: read:"); + if (n != sizeof(siginfo)) + continue; + for (i = 0; i < LEN(dispatchsig); i++) + if (dispatchsig[i].sig == siginfo.ssi_signo) + dispatchsig[i].func(); } } -- cgit v1.2.3-70-g09d2