sinit

suckless init
git clone git://git.2f30.org/sinit.git
Log | Files | Refs | README | LICENSE

commit a9baa02ed953c0a09afd70632610daba6fe9723b
parent 74f1fb86c974ad805614f8d96388c2df7911eb55
Author: sin <sin@2f30.org>
Date:   Sat Feb  8 13:00:06 +0000

No need to use select() - we only have one fd

Diffstat:
sinit.c | 26+++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
diff --git a/sinit.c b/sinit.c @@ -6,7 +6,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/select.h> #include <sys/signalfd.h> #include <sys/stat.h> #include <sys/types.h> @@ -39,9 +38,7 @@ main(void) sigset_t sigset; int sigfd; int i; - int ret; ssize_t n; - fd_set rfds; if (getpid() != 1) return EXIT_FAILURE; @@ -64,23 +61,14 @@ main(void) spawn(rcinitcmd); while (1) { - FD_ZERO(&rfds); - FD_SET(sigfd, &rfds); - ret = select(sigfd + 1, &rfds, NULL, NULL, NULL); - if (ret < 0) - eprintf("sinit: select:"); - if (ret == 0) + n = read(sigfd, &siginfo, sizeof(siginfo)); + if (n < 0) + eprintf("sinit: read:"); + if (n != sizeof(siginfo)) 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(); - } + for (i = 0; i < LEN(dispatchsig); i++) + if (dispatchsig[i].sig == siginfo.ssi_signo) + dispatchsig[i].func(); } return EXIT_SUCCESS;