1 /*
2 * Test that sigreturn() does not corrupt the signal mask.
3 * Block SIGUSR2 and handle SIGUSR1.
4 * Then sigwait() SIGUSR2, which relies on it remaining blocked.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 #include <assert.h>
9 #include <pthread.h>
10 #include <signal.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13
14 int seen_sig = -1;
15
signal_func(int sig)16 static void signal_func(int sig)
17 {
18 seen_sig = sig;
19 }
20
thread_func(void * arg)21 static void *thread_func(void *arg)
22 {
23 kill(getpid(), SIGUSR2);
24 return NULL;
25 }
26
main(void)27 int main(void)
28 {
29 struct sigaction act = {
30 .sa_handler = signal_func,
31 };
32 pthread_t thread;
33 sigset_t set;
34 int sig;
35
36 assert(sigaction(SIGUSR1, &act, NULL) == 0);
37
38 assert(sigemptyset(&set) == 0);
39 assert(sigaddset(&set, SIGUSR2) == 0);
40 assert(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
41
42 kill(getpid(), SIGUSR1);
43 assert(seen_sig == SIGUSR1);
44
45 assert(pthread_create(&thread, NULL, thread_func, NULL) == 0);
46 assert(sigwait(&set, &sig) == 0);
47 assert(sig == SIGUSR2);
48 assert(pthread_join(thread, NULL) == 0);
49
50 return EXIT_SUCCESS;
51 }
52