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