main: reset signal mask and signal handlers at startup

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
This commit is contained in:
Daniel Eklöf 2022-02-02 21:35:39 +01:00
parent 63b12d4cdc
commit 8ca0eaa94c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 19 additions and 0 deletions

View file

@ -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

16
main.c
View file

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