i3bar: Group child processes for signalling
Patch status: merged
Patch by Tony Crisci
Long description:
Set the process group id of the child process by calling `setpgid` after forking and before calling `exec`. The process group ID will be set to the process ID of the forked process. Processes spawned by this child process will also have this group ID. Send signals to the process group with `killpg`. This will send the signal to all of the process group. fixes #1128
To apply this patch, use:
curl http://cr.i3wm.org/patch/339/raw.patch | git am
b/i3bar/src/child.c
24 |
@@ -424,6 +424,7 @@ void start_child(char *command) { |
25 |
dup2(pipe_in[1], STDOUT_FILENO); |
26 |
dup2(pipe_out[0], STDIN_FILENO); |
27 |
|
28 |
+ setpgid(child.pid, 0); |
29 |
execl(_PATH_BSHELL, _PATH_BSHELL, "-c", command, (char*) NULL); |
30 |
return; |
31 |
default: |
32 |
@@ -507,8 +508,8 @@ void send_block_clicked(int button, const char *name, const char *instance, int |
33 |
void kill_child_at_exit(void) { |
34 |
if (child.pid > 0) { |
35 |
if (child.cont_signal > 0 && child.stopped) |
36 |
- kill(child.pid, child.cont_signal); |
37 |
- kill(child.pid, SIGTERM); |
38 |
+ killpg(child.pid, child.cont_signal); |
39 |
+ killpg(child.pid, SIGTERM); |
40 |
} |
41 |
} |
42 |
|
43 |
@@ -520,8 +521,8 @@ void kill_child_at_exit(void) { |
44 |
void kill_child(void) { |
45 |
if (child.pid > 0) { |
46 |
if (child.cont_signal > 0 && child.stopped) |
47 |
- kill(child.pid, child.cont_signal); |
48 |
- kill(child.pid, SIGTERM); |
49 |
+ killpg(child.pid, child.cont_signal); |
50 |
+ killpg(child.pid, SIGTERM); |
51 |
int status; |
52 |
waitpid(child.pid, &status, 0); |
53 |
cleanup(); |
54 |
@@ -535,7 +536,7 @@ void kill_child(void) { |
55 |
void stop_child(void) { |
56 |
if (child.stop_signal > 0 && !child.stopped) { |
57 |
child.stopped = true; |
58 |
- kill(child.pid, child.stop_signal); |
59 |
+ killpg(child.pid, child.stop_signal); |
60 |
} |
61 |
} |
62 |
|
63 |
@@ -546,6 +547,6 @@ void stop_child(void) { |
64 |
void cont_child(void) { |
65 |
if (child.cont_signal > 0 && child.stopped) { |
66 |
child.stopped = false; |
67 |
- kill(child.pid, child.cont_signal); |
68 |
+ killpg(child.pid, child.cont_signal); |
69 |
} |
70 |
} |