Use sigaction instead of signal.
SIGCHLD and SIGALRM are now exclusives (one mask other)
This commit is contained in:
parent
c817b7277b
commit
0a2c1f9d13
31
src/wmfs.c
31
src/wmfs.c
@ -146,6 +146,7 @@ quit(void)
|
|||||||
void
|
void
|
||||||
status_timer(void)
|
status_timer(void)
|
||||||
{
|
{
|
||||||
|
struct sigaction sa;
|
||||||
struct itimerval timer = {
|
struct itimerval timer = {
|
||||||
.it_interval = {
|
.it_interval = {
|
||||||
.tv_usec = 0,
|
.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);
|
setitimer(ITIMER_REAL, &timer, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,17 +410,12 @@ signal_handle(int sig)
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
case SIGCHLD:
|
case SIGCHLD:
|
||||||
/* re-set signal handler and wait childs */
|
/* wait childs */
|
||||||
if (signal(SIGCHLD, &signal_handle) == SIG_ERR)
|
|
||||||
warn("signal(%d)", SIGCHLD);
|
|
||||||
while ((pid = waitpid(-1, NULL, WNOHANG)) > 0)
|
while ((pid = waitpid(-1, NULL, WNOHANG)) > 0)
|
||||||
if (pid == conf.status_pid)
|
if (pid == conf.status_pid)
|
||||||
conf.status_pid = -1;
|
conf.status_pid = -1;
|
||||||
break;
|
break;
|
||||||
case SIGALRM:
|
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) */
|
/* exec status script (only if still not running) */
|
||||||
if (conf.status_pid == (pid_t)-1)
|
if (conf.status_pid == (pid_t)-1)
|
||||||
conf.status_pid = spawn(conf.status_path);
|
conf.status_pid = spawn(conf.status_path);
|
||||||
@ -437,7 +437,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 };
|
struct sigaction sa;
|
||||||
|
|
||||||
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"));
|
||||||
@ -518,17 +518,22 @@ main(int argc, char **argv)
|
|||||||
if(!(dpy = XOpenDisplay(NULL)))
|
if(!(dpy = XOpenDisplay(NULL)))
|
||||||
errx(EXIT_FAILURE, "cannot open X server.");
|
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 */
|
/* Check if an other WM is already running; set the error handler */
|
||||||
XSetErrorHandler(errorhandler);
|
XSetErrorHandler(errorhandler);
|
||||||
|
|
||||||
/* Let's Go ! */
|
/* Let's Go ! */
|
||||||
init();
|
init();
|
||||||
scan();
|
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)
|
if (estatus)
|
||||||
status_timer();
|
status_timer();
|
||||||
mainloop();
|
mainloop();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user