From 78595f1f68a49e49a1ac3a427e040ab9b35fd598 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sun, 24 May 2020 10:33:02 +0200 Subject: [PATCH] Improve handling of nagbar processes Other changes in nagbar_exited: - Remove ERROR from ELOG as it shows up as "ERROR: ERROR:" - Make sure to reset the PID even when the process did not exit normally. - Use ELOG when exitcode != 0 - Remove the not found error: if nagbar is not in $PATH, exec_i3_utility prints an error as well. For the record, I also implemented a more complicated approach with a new watcher data structure: https://github.com/orestisfl/i3/commit/bd3aaf3a333a677433ac046901205086ab58a15c While writing the commit message, it occurred to me to compare watcher->pid with *watcher->data, which fixes the problems mentioned in that patch. Fixes #4104 --- RELEASE-NOTES-next | 1 + src/commands.c | 8 ++++++++ src/util.c | 18 ++++++++++-------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES-next b/RELEASE-NOTES-next index d5db53220..78984c8a3 100644 --- a/RELEASE-NOTES-next +++ b/RELEASE-NOTES-next @@ -42,3 +42,4 @@ working. Please reach out to us in that case! • build: correctly provide auxiliary functions when needed • build: fix issues with parallel build • set _NET_DESKTOP_VIEWPORT after randr changes + • fix a bug with i3-nagbar not starting after it has already started once diff --git a/src/commands.c b/src/commands.c index 8310c8112..3f8c2695e 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1615,8 +1615,16 @@ void cmd_exit(I3_CMD) { */ void cmd_reload(I3_CMD) { LOG("reloading\n"); + kill_nagbar(config_error_nagbar_pid, false); kill_nagbar(command_error_nagbar_pid, false); + /* start_nagbar() will refuse to start a new process if the passed pid is + * set. This will happen when our child watcher is triggered by libev when + * the loop re-starts. However, config errors might be detected before + * that since we will read the config right now with load_configuration. + * See #4104. */ + config_error_nagbar_pid = command_error_nagbar_pid = -1; + load_configuration(NULL, C_RELOAD); x_set_i3_atoms(); /* Send an IPC event just in case the ws names have changed */ diff --git a/src/util.c b/src/util.c index 2ca5b330d..641ce3ce1 100644 --- a/src/util.c +++ b/src/util.c @@ -336,18 +336,20 @@ char *pango_escape_markup(char *input) { static void nagbar_exited(EV_P_ ev_child *watcher, int revents) { ev_child_stop(EV_A_ watcher); + int exitcode = WEXITSTATUS(watcher->rstatus); if (!WIFEXITED(watcher->rstatus)) { - ELOG("ERROR: i3-nagbar did not exit normally.\n"); - return; + ELOG("i3-nagbar (%d) did not exit normally. This is not an error if the config was reloaded while a nagbar was active.\n", watcher->pid); + } else if (exitcode != 0) { + ELOG("i3-nagbar (%d) process exited with status %d\n", watcher->pid, exitcode); + } else { + DLOG("i3-nagbar (%d) process exited with status %d\n", watcher->pid, exitcode); } - int exitcode = WEXITSTATUS(watcher->rstatus); - DLOG("i3-nagbar process exited with status %d\n", exitcode); - if (exitcode == 2) { - ELOG("ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n"); + pid_t *nagbar_pid = watcher->data; + if (*nagbar_pid == watcher->pid) { + /* Only reset if the watched nagbar is the active nagbar */ + *nagbar_pid = -1; } - - *((pid_t *)watcher->data) = -1; } /*