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