1 /******************************************************************************/
2 /* Copyright (c) Crackerjack Project., 2007 */
3 /* */
4 /* This program is free software; you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation; either version 2 of the License, or */
7 /* (at your option) any later version. */
8 /* */
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
12 /* the GNU General Public License for more details. */
13 /* */
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program; if not, write to the Free Software Foundation, */
16 /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
17 /* */
18 /* History: Porting from Crackerjack to LTP is done by */
19 /* Manas Kumar Nayak maknayak@in.ibm.com> */
20 /******************************************************************************/
21
22 /******************************************************************************/
23 /* Description: This tests the rt_sigsuspend() syscall. */
24 /******************************************************************************/
25
26 #include <stdio.h>
27 #include <signal.h>
28 #include <errno.h>
29
30 #include "test.h"
31 #include "linux_syscall_numbers.h"
32 #include "lapi/rt_sigaction.h"
33
34 char *TCID = "rt_sigsuspend01";
35 int TST_TOTAL = 1;
36
cleanup(void)37 static void cleanup(void)
38 {
39 tst_rmdir();
40 }
41
setup(void)42 static void setup(void)
43 {
44 TEST_PAUSE;
45 tst_tmpdir();
46 }
47
sig_handler(int sig)48 static void sig_handler(int sig)
49 {
50 }
51
main(int ac,char ** av)52 int main(int ac, char **av)
53 {
54 sigset_t set, set1, set2;
55 int lc;
56
57 tst_parse_opts(ac, av, NULL, NULL);
58
59 setup();
60
61 for (lc = 0; TEST_LOOPING(lc); ++lc) {
62
63 tst_count = 0;
64
65 if (sigemptyset(&set) < 0)
66 tst_brkm(TFAIL | TERRNO, cleanup, "sigemptyset failed");
67 struct sigaction act, oact;
68 memset(&act, 0, sizeof(act));
69 memset(&oact, 0, sizeof(oact));
70 act.sa_handler = sig_handler;
71
72 TEST(ltp_rt_sigaction(SIGALRM, &act, &oact, SIGSETSIZE));
73 if (TEST_RETURN == -1)
74 tst_brkm(TFAIL | TTERRNO, cleanup,
75 "rt_sigaction failed");
76
77 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
78 &set1, SIGSETSIZE));
79 if (TEST_RETURN == -1)
80 tst_brkm(TFAIL | TTERRNO, cleanup,
81 "rt_sigprocmask failed");
82
83 TEST(alarm(5));
84 int result;
85 TEST(result = ltp_syscall(__NR_rt_sigsuspend, &set,
86 SIGSETSIZE));
87 TEST(alarm(0));
88 if (result == -1 && TEST_ERRNO != EINTR) {
89 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0,
90 &set2, SIGSETSIZE));
91 if (TEST_RETURN == -1) {
92 tst_brkm(TFAIL | TTERRNO, cleanup,
93 "rt_sigprocmask failed");
94 } else if (set1.__val[0] != set2.__val[0]) {
95 tst_brkm(TFAIL | TTERRNO, cleanup,
96 "rt_sigsuspend failed to "
97 "preserve signal mask");
98 } else {
99 tst_resm(TPASS, "rt_sigsuspend PASSED");
100 }
101 } else {
102 tst_resm(TFAIL | TTERRNO, "rt_sigsuspend failed");
103 }
104
105 }
106
107 cleanup();
108
109 tst_exit();
110 }
111