From cbe1c2fe7526307b94ed62a7519ce32e8c1ff638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 3 Feb 2025 07:50:10 +0100 Subject: [PATCH] term: shutdown: special case child terminating due to SIGHUP When closing the window via a compositor shortcut, or clicking the CSD close button, we kill the client application by sending it SIGHUP (and then SIGTERM followed by SIGKILL, if it refuses to die). Many shells either don't catch SIGHUP, causing us to exit with a non-zero value, or they catch it, and then _they_ exit with a non-zero value, causing _us_ to propagate that to the user. This patch changes foot's behavior to "ignore" death-by-sighup, and always exit with value 0. The log message is changed to debug level, for SIGHUP only; other death-by-signal is still logged at the warning level. --- CHANGELOG.md | 3 +++ terminal.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a14b0fab..46a0d754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,9 @@ * Do not try to set a zero width, or height, if the compositor sends a _configure_ event with only one dimension being zero ([#1925][1925]). +* Exit with value `0` when the client process exits due to us sending + it `SIGHUP`. This happens for example when closing the window with + either a compositor shortcut, or clicking the CSD _close_ button. [1925]: https://codeberg.org/dnkl/foot/issues/1925 diff --git a/terminal.c b/terminal.c index 6936ff29..45ab146d 100644 --- a/terminal.c +++ b/terminal.c @@ -1978,7 +1978,11 @@ term_destroy(struct terminal *term) LOG_DBG("slave exited with code %d", ret); } else if (WIFSIGNALED(exit_status)) { ret = WTERMSIG(exit_status); - LOG_WARN("slave exited with signal %d (%s)", ret, strsignal(ret)); + if (ret == SIGHUP) { + LOG_DBG("slave exited with signal %d (%s)", ret, strsignal(ret)); + ret = 0; + } else + LOG_WARN("slave exited with signal %d (%s)", ret, strsignal(ret)); } else { LOG_WARN("slave exited for unknown reason (status = 0x%08x)", exit_status);