diff options
author | 2021-11-21 10:55:20 +0100 | |
---|---|---|
committer | 2021-11-25 12:09:12 +0100 | |
commit | f627cd77d6a889e97eb1e6b889322e70482d441c (patch) | |
tree | 600847a4debe819c340351b766a1ce8c8dc18b65 /swaybar/status_line.c | |
parent | ipc: make `bar <bar_id> mode|hidden_state` behave as documented (diff) | |
download | sway-f627cd77d6a889e97eb1e6b889322e70482d441c.tar.gz sway-f627cd77d6a889e97eb1e6b889322e70482d441c.tar.zst sway-f627cd77d6a889e97eb1e6b889322e70482d441c.zip |
swaybar: signal status command's process group
Make the status command a process group leader and change the kill(2)
calls to target the new process group. Signals sent by swaybar will then
be received by both the status command and its children, if any. While
here, check the result of fork(2).
Without this, children spawned by the status command may not receive the
signals sent by swaybar. As a result, these children may be orphaned on
reload.
The issue could be shown by setting the bar to
bar {
status_command i3status | tee /tmp/i3status.out
}
which would leave orphaned processes for each reload of sway
$ ps o pid,ppid,cmd | grep i3status | grep -v grep
43633 43624 sh -c i3status | tee /tmp/i3status.out
43634 43633 i3status
43635 43633 tee /tmp/i3status.out
$ swaymsg reload
$ ps o pid,ppid,cmd | grep i3status | grep -v grep
43634 1 i3status
43635 1 tee /tmp/i3status.out
43801 43788 sh -c i3status | tee /tmp/i3status.out
43802 43801 i3status
43803 43801 tee /tmp/i3status.out
This fixes #5584.
Diffstat (limited to 'swaybar/status_line.c')
-rw-r--r-- | swaybar/status_line.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/swaybar/status_line.c b/swaybar/status_line.c index ecd91032..a97f3525 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c | |||
@@ -157,7 +157,12 @@ struct status_line *status_line_init(char *cmd) { | |||
157 | assert(!getenv("WAYLAND_SOCKET") && "display must be initialized before " | 157 | assert(!getenv("WAYLAND_SOCKET") && "display must be initialized before " |
158 | " starting `status-command`; WAYLAND_SOCKET should not be set"); | 158 | " starting `status-command`; WAYLAND_SOCKET should not be set"); |
159 | status->pid = fork(); | 159 | status->pid = fork(); |
160 | if (status->pid == 0) { | 160 | if (status->pid < 0) { |
161 | sway_log_errno(SWAY_ERROR, "fork failed"); | ||
162 | exit(1); | ||
163 | } else if (status->pid == 0) { | ||
164 | setpgid(0, 0); | ||
165 | |||
161 | dup2(pipe_read_fd[1], STDOUT_FILENO); | 166 | dup2(pipe_read_fd[1], STDOUT_FILENO); |
162 | close(pipe_read_fd[0]); | 167 | close(pipe_read_fd[0]); |
163 | close(pipe_read_fd[1]); | 168 | close(pipe_read_fd[1]); |
@@ -185,8 +190,8 @@ struct status_line *status_line_init(char *cmd) { | |||
185 | 190 | ||
186 | void status_line_free(struct status_line *status) { | 191 | void status_line_free(struct status_line *status) { |
187 | status_line_close_fds(status); | 192 | status_line_close_fds(status); |
188 | kill(status->pid, status->cont_signal); | 193 | kill(-status->pid, status->cont_signal); |
189 | kill(status->pid, SIGTERM); | 194 | kill(-status->pid, SIGTERM); |
190 | waitpid(status->pid, NULL, 0); | 195 | waitpid(status->pid, NULL, 0); |
191 | if (status->protocol == PROTOCOL_I3BAR) { | 196 | if (status->protocol == PROTOCOL_I3BAR) { |
192 | struct i3bar_block *block, *tmp; | 197 | struct i3bar_block *block, *tmp; |