Fork two times to avoid generating zombies

This commit is contained in:
Bastien Dejean 2013-11-08 21:10:37 +01:00
parent 4451d8f0e7
commit d9face09c9

17
rule.c
View file

@ -25,6 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h>
#include "bspwm.h" #include "bspwm.h"
#include "ewmh.h" #include "ewmh.h"
#include "window.h" #include "window.h"
@ -141,16 +142,20 @@ bool schedule_rules(xcb_window_t win, rule_consequence_t *csq)
if (pid == 0) { if (pid == 0) {
if (dpy != NULL) if (dpy != NULL)
close(xcb_get_file_descriptor(dpy)); close(xcb_get_file_descriptor(dpy));
dup2(fds[1], 1); if (fork() == 0) {
close(fds[0]); dup2(fds[1], 1);
char wid[SMALEN]; close(fds[0]);
snprintf(wid, sizeof(wid), "%i", win); char wid[SMALEN];
execl(rule_command, rule_command, wid, NULL); snprintf(wid, sizeof(wid), "%i", win);
err("Couldn't spawn rule command.\n"); execl(rule_command, rule_command, wid, NULL);
err("Couldn't spawn rule command.\n");
}
exit(EXIT_SUCCESS);
} else if (pid > 0) { } else if (pid > 0) {
close(fds[1]); close(fds[1]);
pending_rule_t *pr = make_pending_rule(fds[0], win, csq); pending_rule_t *pr = make_pending_rule(fds[0], win, csq);
add_pending_rule(pr); add_pending_rule(pr);
wait(NULL);
} }
return (pid != -1); return (pid != -1);
} }