From 6882cfb986660e9f04d4989720873d256e5f97bf Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Tue, 7 Dec 2010 00:12:54 +0100 Subject: [PATCH] Only one handler for signals --- src/init.c | 12 ------------ src/wmfs.c | 29 ++++++++++++++++++++++------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/init.c b/src/init.c index 2e8e168..21b01e0 100644 --- a/src/init.c +++ b/src/init.c @@ -55,24 +55,12 @@ const func_name_list_t layout_list[] = { NULL, NULL } }; -static void sigchld(int); - -static void -sigchld(int sig) -{ - (void)sig; - if (signal(SIGCHLD, sigchld) == SIG_ERR) - warn("signal(SIGCHLD)"); - while (waitpid(-1, NULL, WNOHANG) > 0); -} - /** Init WMFS */ void init(void) { /* First init */ - sigchld(0); ewmh_init_hints(); init_conf(); init_gc(); diff --git a/src/wmfs.c b/src/wmfs.c index bb65499..305fa4f 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -32,6 +32,8 @@ #include "wmfs.h" +static void signal_handle(int); + int errorhandler(Display *d, XErrorEvent *event) { @@ -399,13 +401,24 @@ update_status(void) /** Signal handle function */ -void +static void signal_handle(int sig) { - (void)sig; - exiting = True; - quit(); - exit(EXIT_SUCCESS); + switch (sig) + { + case SIGQUIT: + case SIGTERM: + exiting = True; + quit(); + exit(EXIT_SUCCESS); + break; + case SIGCHLD: + /* re-set signal handler and wait childs */ + if (signal(SIGCHLD, &signal_handle) == SIG_ERR) + warn("signal(%d)", SIGCHLD); + while (waitpid(-1, NULL, WNOHANG) > 0); + break; + } return; } @@ -422,6 +435,7 @@ main(int argc, char **argv) char *ol = "csgVS"; extern char *optarg; extern int optind; + int sigs[] = { SIGTERM, SIGQUIT, SIGCHLD }; argv_global = xstrdup(argv[0]); sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME")); @@ -503,8 +517,9 @@ main(int argc, char **argv) errx(EXIT_FAILURE, "cannot open X server."); /* Set signal handler */ - (void)signal(SIGTERM, &signal_handle); - (void)signal(SIGINT, &signal_handle); + for (i = sigs[0]; i < (int)LEN(sigs); i++) + if (signal(sigs[i], &signal_handle) == SIG_ERR) + warn("signal(%d)", sigs[i]); /* Check if an other WM is already running; set the error handler */ XSetErrorHandler(errorhandler);