Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Move nagbar cleanup to i3_exit
Otherwise, each time we start a nagbar, a cleanup handler is created.
However, each of these handlers tries to kill the same process (->data
is a pointer to config_error_nagbar_pid / command_error_nagbar_pid).

With this commit, both potential nagbar processes are killed once.
  • Loading branch information
orestisfl committed May 24, 2020
1 parent 78595f1 commit 00ffa68
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/main.c
Expand Up @@ -182,6 +182,10 @@ static void i3_exit(void) {
unlink(config.ipc_socket_path);
xcb_disconnect(conn);

/* If a nagbar is active, kill it */
kill_nagbar(config_error_nagbar_pid, false);
kill_nagbar(command_error_nagbar_pid, false);

/* We need ev >= 4 for the following code. Since it is not *that* important (it
* only makes sure that there are no i3-nagbar instances left behind) we still
* support old systems with libev 3. */
Expand Down
20 changes: 0 additions & 20 deletions src/util.c
Expand Up @@ -352,19 +352,6 @@ static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
}
}

/*
* Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
* SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
*
*/
static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
pid_t *nagbar_pid = (pid_t *)watcher->data;
if (*nagbar_pid != -1) {
LOG("Sending SIGKILL (%d) to i3-nagbar with PID %d\n", SIGKILL, *nagbar_pid);
kill(*nagbar_pid, SIGKILL);
}
}

/*
* Starts an i3-nagbar instance with the given parameters. Takes care of
* handling SIGCHLD and killing i3-nagbar when i3 exits.
Expand Down Expand Up @@ -397,13 +384,6 @@ void start_nagbar(pid_t *nagbar_pid, char *argv[]) {
ev_child_init(child, &nagbar_exited, *nagbar_pid, 0);
child->data = nagbar_pid;
ev_child_start(main_loop, child);

/* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
* still running) */
ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
ev_cleanup_init(cleanup, nagbar_cleanup);
cleanup->data = nagbar_pid;
ev_cleanup_start(main_loop, cleanup);
}

/*
Expand Down

0 comments on commit 00ffa68

Please sign in to comment.