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

Commit

Permalink
Improve handling of nagbar processes
Browse files Browse the repository at this point in the history
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:
orestisfl/i3@bd3aaf3
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
  • Loading branch information
orestisfl committed May 24, 2020
1 parent 6e087d4 commit 78595f1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES-next
Expand Up @@ -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
8 changes: 8 additions & 0 deletions src/commands.c
Expand Up @@ -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 */
Expand Down
18 changes: 10 additions & 8 deletions src/util.c
Expand Up @@ -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;
}

/*
Expand Down

0 comments on commit 78595f1

Please sign in to comment.