• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_sigaction() syscall                         */
24 /*		rt_sigaction alters an action taken by a process on receipt   */
25 /* 		of a particular signal. The action is specified by the        */
26 /*		sigaction structure. The previous action on the signal is     */
27 /*		saved in oact.sigsetsize should indicate the size of a        */
28 /*		sigset_t type.                       			      */
29 /******************************************************************************/
30 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <signal.h>
35 #include <errno.h>
36 #include <sys/syscall.h>
37 #include <string.h>
38 
39 #include "test.h"
40 #include "lapi/syscalls.h"
41 #include "lapi/rt_sigaction.h"
42 
43 char *TCID = "rt_sigaction01";
44 static int testno;
45 int TST_TOTAL = 1;
46 
cleanup(void)47 static void cleanup(void)
48 {
49 	tst_rmdir();
50 }
51 
setup(void)52 static void setup(void)
53 {
54 	TEST_PAUSE;
55 	tst_tmpdir();
56 }
57 
58 static int test_flags[] =
59     { SA_RESETHAND | SA_SIGINFO, SA_RESETHAND, SA_RESETHAND | SA_SIGINFO,
60 SA_RESETHAND | SA_SIGINFO, SA_NOMASK };
61 char *test_flags_list[] =
62     { "SA_RESETHAND|SA_SIGINFO", "SA_RESETHAND", "SA_RESETHAND|SA_SIGINFO",
63 "SA_RESETHAND|SA_SIGINFO", "SA_NOMASK" };
64 
handler(int sig)65 static void handler(int sig)
66 {
67 	tst_resm(TINFO, "Signal Handler Called with signal number %d\n", sig);
68 	return;
69 }
70 
set_handler(int sig,int sig_to_mask,int mask_flags)71 static int set_handler(int sig, int sig_to_mask, int mask_flags)
72 {
73 	struct sigaction sa, oldaction;
74 
75 	sa.sa_handler = (void *)handler;
76 	sa.sa_flags = mask_flags;
77 	sigemptyset(&sa.sa_mask);
78 	sigaddset(&sa.sa_mask, sig);
79 
80 	return ltp_rt_sigaction(sig, &sa, &oldaction, SIGSETSIZE);
81 }
82 
main(int ac,char ** av)83 int main(int ac, char **av)
84 {
85 	unsigned int flag;
86 	int signal;
87 	int lc;
88 
89 	tst_parse_opts(ac, av, NULL, NULL);
90 
91 	setup();
92 
93 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
94 
95 		tst_count = 0;
96 
97 		for (testno = 0; testno < TST_TOTAL; ++testno) {
98 
99 			for (signal = SIGRTMIN; signal <= SIGRTMAX; signal++) {
100 				for (flag = 0;
101 				     flag <
102 				      ARRAY_SIZE(test_flags); flag++) {
103 
104 					TEST(set_handler
105 					     (signal, 0, test_flags[flag]));
106 
107 					if (TEST_RETURN == 0) {
108 						tst_resm(TINFO, "signal: %d ",
109 							 signal);
110 						tst_resm(TPASS,
111 							 "rt_sigaction call succeeded: result = %ld ",
112 							 TEST_RETURN);
113 						tst_resm(TINFO,
114 							 "sa.sa_flags = %s ",
115 							 test_flags_list[flag]);
116 						kill(getpid(), signal);
117 					} else {
118 						tst_resm(TFAIL | TTERRNO,
119 							 "rt_sigaction call "
120 							 "failed");
121 					}
122 
123 				}
124 
125 			}
126 
127 		}
128 
129 	}
130 	cleanup();
131 	tst_exit();
132 }
133