Terminate children when freeing output container

This commit is contained in:
Mikkel Oscar Lyderik 2015-12-18 18:02:39 +01:00
parent ede27eabc5
commit 90ff36cab8
3 changed files with 18 additions and 8 deletions

View file

@ -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.

View file

@ -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) {
@ -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();
@ -496,13 +506,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);

View file

@ -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);
}