From: Michael Stapelberg Date: Sun, 11 Sep 2011 20:49:35 +0000 (+0100) Subject: Kill left-over i3-nagbar processes on 'exit' X-Git-Tag: 4.1~166^2~4 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d03dffe012ca1807b396270a4b145bfb0ae6d63a;p=i3%2Fi3 Kill left-over i3-nagbar processes on 'exit' --- diff --git a/src/cfgparse.y b/src/cfgparse.y index 7efecc92..ca2d0710 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -240,6 +240,18 @@ static void nagbar_exited(EV_P_ ev_child *watcher, int revents) { configerror_pid = -1; } +/* + * 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) { + if (configerror_pid != -1) { + LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", configerror_pid); + kill(configerror_pid, SIGKILL); + } +} + /* * Starts an i3-nagbar process which alerts the user that his configuration * file contains one or more errors. Also offers two buttons: One to launch an @@ -283,6 +295,12 @@ static void start_configerror_nagbar(const char *config_path) { ev_child *child = smalloc(sizeof(ev_child)); ev_child_init(child, &nagbar_exited, configerror_pid, 0); 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); + ev_cleanup_start(main_loop, cleanup); } /* diff --git a/src/main.c b/src/main.c index aee95f75..ea02bb6e 100644 --- a/src/main.c +++ b/src/main.c @@ -163,6 +163,14 @@ static void xkb_got_event(EV_P_ struct ev_io *w, int revents) { DLOG("Done\n"); } +/* + * Exit handler which destroys the main_loop. Will trigger cleanup handlers. + * + */ +static void i3_exit() { + ev_loop_destroy(main_loop); +} + int main(int argc, char *argv[]) { //parse_cmd("[ foo ] attach, attach ; focus"); int screens; @@ -529,5 +537,9 @@ int main(int argc, char *argv[]) { start_application(exec_always->command); } + /* Make sure to destroy the event loop to invoke the cleeanup callbacks + * when calling exit() */ + atexit(i3_exit); + ev_loop(main_loop, 0); }