aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorCraig Barnes <craigbarnes@protonmail.com>2022-02-12 12:04:57 +0000
committerCraig Barnes <craigbarnes@protonmail.com>2022-02-12 12:26:42 +0000
commit23cf80667a36aaff1865fc50afab3f98a796cf14 (patch)
tree92970245488cdd76c0fe06eb93d1b2d15f8007fe /terminal.c
parentosc: don’t damage the entire view on a single color palette update (diff)
Explicitly initialize sigaction::sa_mask members with sigemptyset(3)
Not doing so before calling sigaction(3) is "undefined" according to POSIX[1]: > Applications shall call either sigemptyset() or sigfillset() at least > once for each object of type sigset_t prior to any other use of that > object. If such an object is not initialized in this way, but is > nonetheless supplied as an argument to any of pthread_sigmask(), > sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), > sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or > sigwaitinfo(), the results are undefined. The use of designated initializers means that sa_mask members were still being initialized, but sigset_t is an opaque type and implicit initialization doesn't necessarily produce the same results as using sigemptyset(3) (although it typically does on most implementations). [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/terminal.c b/terminal.c
index 66c523df..f6d8f814 100644
--- a/terminal.c
+++ b/terminal.c
@@ -1716,7 +1716,9 @@ term_destroy(struct terminal *term)
* course only applies to a 'foot --server' instance, where
* there might be other terminals running.
*/
- sigaction(SIGALRM, &(const struct sigaction){.sa_handler = &sig_alarm}, NULL);
+ struct sigaction action = {.sa_handler = &sig_alarm};
+ sigemptyset(&action.sa_mask);
+ sigaction(SIGALRM, &action, NULL);
alarm(60);
while (true) {
@@ -1740,7 +1742,8 @@ term_destroy(struct terminal *term)
/* Cancel alarm */
alarm(0);
- sigaction(SIGALRM, &(const struct sigaction){.sa_handler = SIG_DFL}, NULL);
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGALRM, &action, NULL);
}
ret = EXIT_FAILURE;