diff options
| author | Ilya Leoshkevich <iii@linux.ibm.com> | 2024-11-08 15:50:04 +0100 |
|---|---|---|
| committer | Richard Henderson <richard.henderson@linaro.org> | 2024-11-16 08:42:24 -0800 |
| commit | ef7e76a2cdc116719ad9c67d4f44dee0016f923c (patch) | |
| tree | 38103429626f247968d9f85910490cbc3e98dcc9 /tests/tcg/multiarch/sigreturn-sigmask.c | |
| parent | fb7f3572b111ffb6c2dd2c7f6c5b4dc57dd8a3f5 (diff) | |
| download | focaccia-qemu-ef7e76a2cdc116719ad9c67d4f44dee0016f923c.tar.gz focaccia-qemu-ef7e76a2cdc116719ad9c67d4f44dee0016f923c.zip | |
tests/tcg: Test that sigreturn() does not corrupt the signal mask
Add a small test to prevent regressions. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Message-ID: <20241108145237.37377-2-iii@linux.ibm.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'tests/tcg/multiarch/sigreturn-sigmask.c')
| -rw-r--r-- | tests/tcg/multiarch/sigreturn-sigmask.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/tcg/multiarch/sigreturn-sigmask.c b/tests/tcg/multiarch/sigreturn-sigmask.c new file mode 100644 index 0000000000..e6cc904898 --- /dev/null +++ b/tests/tcg/multiarch/sigreturn-sigmask.c @@ -0,0 +1,51 @@ +/* + * Test that sigreturn() does not corrupt the signal mask. + * Block SIGUSR2 and handle SIGUSR1. + * Then sigwait() SIGUSR2, which relies on it remaining blocked. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include <assert.h> +#include <pthread.h> +#include <signal.h> +#include <stdlib.h> +#include <unistd.h> + +int seen_sig = -1; + +static void signal_func(int sig) +{ + seen_sig = sig; +} + +static void *thread_func(void *arg) +{ + kill(getpid(), SIGUSR2); + return NULL; +} + +int main(void) +{ + struct sigaction act = { + .sa_handler = signal_func, + }; + pthread_t thread; + sigset_t set; + int sig; + + assert(sigaction(SIGUSR1, &act, NULL) == 0); + + assert(sigemptyset(&set) == 0); + assert(sigaddset(&set, SIGUSR2) == 0); + assert(sigprocmask(SIG_BLOCK, &set, NULL) == 0); + + kill(getpid(), SIGUSR1); + assert(seen_sig == SIGUSR1); + + assert(pthread_create(&thread, NULL, thread_func, NULL) == 0); + assert(sigwait(&set, &sig) == 0); + assert(sig == SIGUSR2); + assert(pthread_join(thread, NULL) == 0); + + return EXIT_SUCCESS; +} |