From 0a2c1f9d133369819d7293e0191e9a1e7538f4c6 Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Tue, 4 Jan 2011 03:02:29 +0100 Subject: [PATCH] Use sigaction instead of signal. SIGCHLD and SIGALRM are now exclusives (one mask other) --- src/wmfs.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/wmfs.c b/src/wmfs.c index eced565..2b62ede 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -146,6 +146,7 @@ quit(void) void status_timer(void) { + struct sigaction sa; struct itimerval timer = { .it_interval = { .tv_usec = 0, @@ -157,7 +158,11 @@ status_timer(void) }, }; - signal(SIGALRM, &signal_handle); + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = signal_handle; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGCHLD); + sigaction(SIGALRM, &sa, NULL); setitimer(ITIMER_REAL, &timer, NULL); } @@ -405,17 +410,12 @@ signal_handle(int sig) exit(EXIT_SUCCESS); break; case SIGCHLD: - /* re-set signal handler and wait childs */ - if (signal(SIGCHLD, &signal_handle) == SIG_ERR) - warn("signal(%d)", SIGCHLD); + /* wait childs */ while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) if (pid == conf.status_pid) conf.status_pid = -1; break; case SIGALRM: - /* re-set signal handler */ - if (signal(SIGALRM, &signal_handle) == SIG_ERR) - warn("signal(%d)", SIGALRM); /* exec status script (only if still not running) */ if (conf.status_pid == (pid_t)-1) conf.status_pid = spawn(conf.status_path); @@ -437,7 +437,7 @@ main(int argc, char **argv) char *ol = "csgVS"; extern char *optarg; extern int optind; - int sigs[] = { SIGTERM, SIGQUIT, SIGCHLD }; + struct sigaction sa; argv_global = xstrdup(argv[0]); sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME")); @@ -518,17 +518,22 @@ main(int argc, char **argv) if(!(dpy = XOpenDisplay(NULL))) errx(EXIT_FAILURE, "cannot open X server."); - /* Set signal handler */ - for (i = 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); /* Let's Go ! */ init(); scan(); + + /* set signal handler */ + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = signal_handle; + sigemptyset(&sa.sa_mask); + sigaction(SIGQUIT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + sigaddset(&sa.sa_mask, SIGALRM); + sigaction(SIGCHLD, &sa, NULL); + if (estatus) status_timer(); mainloop();