aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-22 05:14:38 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-22 05:14:38 +0200
commit9d6ea5100b404ae777d7a45fc7c3e0892d06b7ba (patch)
tree605afd6d33cc0c050302d4f8dccc99b03eb8a93e
parent4fec9b8fdfc664df12ac67dde2df5e09b8b2b9bb (diff)
Daemonize async process to automatically reap the child when it dies
-rw-r--r--src/window_manager.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/window_manager.c b/src/window_manager.c
index 07d15af..3adb005 100644
--- a/src/window_manager.c
+++ b/src/window_manager.c
@@ -35,10 +35,17 @@ static void spawn(Display *dpy, char *const args[]) {
if (dpy)
close(ConnectionNumber(dpy));
setsid();
- execvp(args[0], args);
- fprintf(stderr, "vrwm: execvp %s\n", args[0]);
- perror("failed");
- exit(1);
+ signal(SIGHUP, SIG_IGN);
+
+ // Daemonize child to make the parent the init process which will reap the zombie child
+ pid_t second_child = fork();
+ if(second_child == 0) { // child
+ execvp(args[0], (char* const*)args);
+ perror("execvp");
+ _exit(127);
+ } else if(second_child != -1) {
+ _exit(0);
+ }
}
}