main: --server: don’t exit with code 0 on failure

A foot --server instance would exit with code 0, even on failure, if
the number of currently open terminal instances were 0.

This is because ‘ret’ assumed failure, and then tried to set it to
‘success’ after the even loop had terminated, basted on the server’s
current state.

Fix by:

* set ‘ret’ to success just before entering the event loop
* set ‘ret’ to failure when we detect an FDM failure
* don’t try to second-guess success/failure after having exited the
  event loop

Closes #943
This commit is contained in:
Daniel Eklöf 2022-02-16 22:40:51 +01:00
parent 6940d2047e
commit 8fa16f616c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 7 additions and 4 deletions

View file

@ -69,6 +69,9 @@
(https://codeberg.org/dnkl/foot/issues/924).
* Crash in `pipe-scrollback`
(https://codeberg.org/dnkl/foot/issues/926).
* Exit code being 0 when a foot server with no open windows terminate
due to e.g. a Wayland connection failure
(https://codeberg.org/dnkl/foot/issues/943).
### Security

8
main.c
View file

@ -642,14 +642,14 @@ main(int argc, char *const *argv)
goto out;
}
ret = EXIT_SUCCESS;
while (likely(!aborted && (as_server || tll_length(wayl->terms) > 0))) {
if (unlikely(!fdm_poll(fdm)))
if (unlikely(!fdm_poll(fdm))) {
ret = foot_exit_failure;
break;
}
}
if (aborted || tll_length(wayl->terms) == 0)
ret = EXIT_SUCCESS;
out:
free(_cwd);
server_destroy(server);