Refactor sighandler

You can't handle SIGKILL. Given we have control over which
signals are passed to the sighandler, it's enough to catch SIGCHLD
and do standard behaviour than building a big switch for that.
This commit is contained in:
FRIGN 2014-08-07 17:24:39 +02:00
parent 92b8bc27da
commit a345c63a59

15
quark.c
View file

@ -459,20 +459,12 @@ serve(int fd) {
void void
sighandler(int sig) { sighandler(int sig) {
switch(sig) { if (sig == SIGCHLD) {
default: break; while(0 < waitpid(-1, NULL, WNOHANG));
case SIGHUP: } else {
case SIGINT:
case SIGQUIT:
case SIGABRT:
case SIGTERM:
logerrmsg("received signal: %s, closing down\n", strsignal(sig)); logerrmsg("received signal: %s, closing down\n", strsignal(sig));
close(fd); close(fd);
running = 0; running = 0;
break;
case SIGCHLD:
while(0 < waitpid(-1, NULL, WNOHANG));
break;
} }
} }
@ -514,7 +506,6 @@ main(int argc, char *argv[]) {
signal(SIGQUIT, sighandler); signal(SIGQUIT, sighandler);
signal(SIGABRT, sighandler); signal(SIGABRT, sighandler);
signal(SIGTERM, sighandler); signal(SIGTERM, sighandler);
signal(SIGKILL, sighandler);
/* init */ /* init */
setbuf(stdout, NULL); /* unbuffered stdout */ setbuf(stdout, NULL); /* unbuffered stdout */