From 8ca0eaa94c08961f955caf54bd5407d5ef53610b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 2 Feb 2022 21:35:39 +0100 Subject: [PATCH] main: reset signal mask and signal handlers at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures processes spawned by us (e.g. the shell, new terminal instances etc) don’t inherit a flawed signal mask, or having signals unknowingly ignored. Closes #854 --- CHANGELOG.md | 3 +++ main.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3497d439..4b3b95c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,9 @@ (https://codeberg.org/dnkl/foot/issues/379). * Line-based selections now include a trailing newline when copied (https://codeberg.org/dnkl/foot/issues/869). +* Foot now clears the signal mask and resets all signal handlers to + their default handlers at startup + (https://codeberg.org/dnkl/foot/issues/854). ### Deprecated diff --git a/main.c b/main.c index 7d57c641..9a87678e 100644 --- a/main.c +++ b/main.c @@ -152,6 +152,20 @@ print_pid(const char *pid_file, bool *unlink_at_exit) return false; } +static void +sanitize_signals(void) +{ + sigset_t mask; + sigemptyset(&mask); + sigprocmask(SIG_SETMASK, &mask, NULL); + + struct sigaction dfl = {.sa_handler = SIG_DFL}; + sigemptyset(&dfl.sa_mask); + + for (int i = 1; i < SIGRTMAX; i++) + sigaction(i, &dfl, NULL); +} + int main(int argc, char *const *argv) { @@ -160,6 +174,8 @@ main(int argc, char *const *argv) static const int foot_exit_failure = -26; int ret = foot_exit_failure; + sanitize_signals(); + /* XDG startup notifications */ const char *token = getenv("XDG_ACTIVATION_TOKEN"); unsetenv("XDG_ACTIVATION_TOKEN");