From 00ffa68a6c9c6849714f7387f75a63de02ce9311 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sun, 24 May 2020 12:57:35 +0200 Subject: [PATCH] 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. --- src/main.c | 4 ++++ src/util.c | 20 -------------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/main.c b/src/main.c index d9b10ecb4..83b3e1819 100644 --- a/src/main.c +++ b/src/main.c @@ -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. */ diff --git a/src/util.c b/src/util.c index 641ce3ce1..cf7f41c8a 100644 --- a/src/util.c +++ b/src/util.c @@ -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. @@ -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); } /*