Skip to content

Commit

Permalink
Terminate children when freeing output container
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkeloscar committed Dec 18, 2015
1 parent 24fbcbc commit f140789
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ int sway_mouse_binding_cmp_buttons(const void *a, const void *b);
void free_sway_mouse_binding(struct sway_mouse_binding *smb);

void load_swaybars(swayc_t *output, int output_idx);
void terminate_swaybars(list_t *pids);
void terminate_swaybg(pid_t pid);

/**
* Allocate and initialize default bar configuration.
Expand Down
20 changes: 12 additions & 8 deletions sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i
list_add(output->bar_pids, pid);
}

static void terminate_swaybars(list_t *pids) {
void terminate_swaybars(list_t *pids) {
int i, ret;
pid_t *pid;
for (i = 0; i < pids->length; ++i) {
Expand All @@ -411,6 +411,16 @@ static void terminate_swaybars(list_t *pids) {
}
}

void terminate_swaybg(pid_t pid) {
int ret = kill(pid, SIGTERM);
if (ret != 0) {
sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", pid);
} else {
int status;
waitpid(pid, &status, 0);
}
}

void load_swaybars(swayc_t *output, int output_idx) {
// Check for bars
list_t *bars = create_list();
Expand Down Expand Up @@ -498,13 +508,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
if (oc && oc->background) {

if (output->bg_pid != 0) {
int ret = kill(output->bg_pid, SIGTERM);
if (ret != 0) {
sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", output->bg_pid);
} else {
int status;
waitpid(output->bg_pid, &status, 0);
}
terminate_swaybg(output->bg_pid);
}

sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background);
Expand Down
4 changes: 4 additions & 0 deletions sway/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ static void free_swayc(swayc_t *cont) {
free(cont->app_id);
}
if (cont->bar_pids) {
terminate_swaybars(cont->bar_pids);
free_flat_list(cont->bar_pids);
}
if (cont->bg_pid != 0) {
terminate_swaybg(cont->bg_pid);
}
free(cont);
}

Expand Down

0 comments on commit f140789

Please sign in to comment.