Fork two times to avoid zombies

The idea comes from:
    http://lubutu.com/code/spawning-in-unix
This commit is contained in:
Bastien Dejean 2012-11-05 10:27:40 +01:00
parent 6a6bccb152
commit d7b0943afe

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <xcb/xcb.h>
#include <xcb/xcb_event.h>
#include "bspwm.h"
@ -15,16 +16,18 @@ void run_autostart(void)
snprintf(path, sizeof(path), "%s/%s/%s", getenv("XDG_CONFIG_HOME"), WM_NAME, AUTOSTART_FILE);
if (fork() != 0)
return;
if (fork() == 0) {
if (dpy != NULL)
close(xcb_get_file_descriptor(dpy));
if (fork() == 0) {
setsid();
execl(path, path, NULL);
err("could not run autostart file\n");
}
exit(EXIT_SUCCESS);
}
if (dpy != NULL)
close(xcb_get_file_descriptor(dpy));
setsid();
execl(path, path, NULL);
err("could not run autostart file\n");
wait(NULL);
}
void load_settings(void)