Handle signals TERM, QUIT and CHLD for zombies
This commit is contained in:
parent
69391afed8
commit
25dec6073c
14
src/util.c
14
src/util.c
@ -108,16 +108,12 @@ spawn(const char *format, ...)
|
||||
if(!(sh = getenv("SHELL")) || sh[0] != '/')
|
||||
sh = "/bin/sh";
|
||||
|
||||
if((pid = fork()) == 0)
|
||||
if(!(pid = fork()))
|
||||
{
|
||||
if((pid = fork()) == 0)
|
||||
{
|
||||
setsid();
|
||||
if (execl(sh, sh, "-c", cmd, (char*)NULL) == -1)
|
||||
warnl("execl(sh -c %s)", cmd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
setsid();
|
||||
if (execl(sh, sh, "-c", cmd, (char*)NULL) == -1)
|
||||
warnl("execl(sh -c %s)", cmd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if (pid == -1)
|
||||
warnl("fork");
|
||||
|
||||
26
src/wmfs.c
26
src/wmfs.c
@ -5,6 +5,8 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/cursorfont.h>
|
||||
|
||||
@ -538,6 +540,21 @@ exec_uicb_function(Display *dpy, Window root, char *func, char *cmd)
|
||||
XSync(dpy, False);
|
||||
}
|
||||
|
||||
static void
|
||||
signal_handle(int sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case SIGQUIT:
|
||||
case SIGTERM:
|
||||
W->flags &= ~WMFS_RUNNING;
|
||||
break;
|
||||
case SIGCHLD:
|
||||
while(waitpid(-1, NULL, WNOHANG) > 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -545,6 +562,7 @@ main(int argc, char **argv)
|
||||
bool r;
|
||||
Display *dpy;
|
||||
char path[MAX_PATH_LEN] = { 0 };
|
||||
struct sigaction sa;
|
||||
(void)argc;
|
||||
|
||||
sprintf(path, "%s/"CONFIG_DEFAULT_PATH, getenv("HOME"));
|
||||
@ -600,6 +618,14 @@ main(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
|
||||
/* Core */
|
||||
wmfs_init();
|
||||
wmfs_scan();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user