Only one handler for signals

This commit is contained in:
Philippe Pepiot
2010-12-07 00:12:54 +01:00
parent 9e457b3832
commit 6882cfb986
2 changed files with 22 additions and 19 deletions

View File

@@ -55,24 +55,12 @@ const func_name_list_t layout_list[] =
{ NULL, NULL } { 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 /** Init WMFS
*/ */
void void
init(void) init(void)
{ {
/* First init */ /* First init */
sigchld(0);
ewmh_init_hints(); ewmh_init_hints();
init_conf(); init_conf();
init_gc(); init_gc();

View File

@@ -32,6 +32,8 @@
#include "wmfs.h" #include "wmfs.h"
static void signal_handle(int);
int int
errorhandler(Display *d, XErrorEvent *event) errorhandler(Display *d, XErrorEvent *event)
{ {
@@ -399,13 +401,24 @@ update_status(void)
/** Signal handle function /** Signal handle function
*/ */
void static void
signal_handle(int sig) signal_handle(int sig)
{ {
(void)sig; switch (sig)
exiting = True; {
quit(); case SIGQUIT:
exit(EXIT_SUCCESS); 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; return;
} }
@@ -422,6 +435,7 @@ main(int argc, char **argv)
char *ol = "csgVS"; char *ol = "csgVS";
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
int sigs[] = { SIGTERM, SIGQUIT, SIGCHLD };
argv_global = xstrdup(argv[0]); argv_global = xstrdup(argv[0]);
sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME")); sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME"));
@@ -503,8 +517,9 @@ main(int argc, char **argv)
errx(EXIT_FAILURE, "cannot open X server."); errx(EXIT_FAILURE, "cannot open X server.");
/* Set signal handler */ /* Set signal handler */
(void)signal(SIGTERM, &signal_handle); for (i = sigs[0]; i < (int)LEN(sigs); i++)
(void)signal(SIGINT, &signal_handle); 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 */ /* Check if an other WM is already running; set the error handler */
XSetErrorHandler(errorhandler); XSetErrorHandler(errorhandler);