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");