1 /******************************************************************************/
2 /* Copyright (c) Crackerjack Project., 2007                                   */
3 /*                                                                            */
4 /* History:     Porting from Crackerjack to LTP is done by                    */
5 /*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
6 /******************************************************************************/
7 
8 /*
9  * Description: This tests the rt_sigsuspend() syscall.
10  *
11  * Waits for SIGALRM in rt_sigsuspend() then checks that process mask wasn't
12  * modified.
13  */
14 
15 #include <signal.h>
16 #include <errno.h>
17 
18 #include "tst_test.h"
19 #include "lapi/syscalls.h"
20 #include "lapi/safe_rt_signal.h"
21 
sig_handler(int sig)22 static void sig_handler(int sig)
23 {
24 	(void) sig;
25 }
26 
verify_rt_sigsuspend(void)27 static void verify_rt_sigsuspend(void)
28 {
29 	int i;
30 	sigset_t set, set1, set2;
31 	struct sigaction act = {.sa_handler = sig_handler};
32 
33 	if (sigemptyset(&set) < 0)
34 		tst_brk(TFAIL | TERRNO, "sigemptyset failed");
35 
36 	SAFE_RT_SIGACTION(SIGALRM, &act, NULL, SIGSETSIZE);
37 
38 	SAFE_RT_SIGPROCMASK(0, NULL, &set1, SIGSETSIZE);
39 
40 	alarm(1);
41 
42 	TEST(tst_syscall(__NR_rt_sigsuspend, &set, SIGSETSIZE));
43 
44 	alarm(0);
45 
46 	if (TST_RET != -1)
47 		tst_brk(TFAIL, "rt_sigsuspend returned %ld", TST_RET);
48 
49 	if (TST_ERR != EINTR)
50 		tst_brk(TFAIL | TTERRNO, "rt_sigsuspend() failed unexpectedly");
51 
52 	tst_res(TPASS, "rt_sigsuspend() returned with -1 and EINTR");
53 
54 	SAFE_RT_SIGPROCMASK(0, NULL, &set2, SIGSETSIZE);
55 	for (i = 1; i < SIGRTMAX; i++) {
56 		if (i >= __SIGRTMIN && i < SIGRTMIN)
57 			continue;
58 		if (sigismember(&set1, i) != sigismember(&set2, i))
59 			tst_brk(TFAIL, "signal mask not preserved");
60 	}
61 	tst_res(TPASS, "signal mask preserved");
62 }
63 
64 static struct tst_test test = {
65 	.test_all = verify_rt_sigsuspend,
66 };
67