• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  *  AUTHOR          : Bob Clark
4  *  CO-PILOT        : Barrie Kletscher
5  *  DATE STARTED    : 9/26/86
6  * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of version 2 of the GNU General Public License as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it would be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * Further, this software is distributed without any warranty that it is
17  * free of the rightful claim of any third person regarding infringement
18  * or the like.  Any license provided herein, whether implied or
19  * otherwise, applies only to this software file.  Patent licenses, if
20  * any, provided herein do not apply to combinations of this program with
21  * other software, or any other product whatsoever.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, write the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  *
27  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
28  * Mountain View, CA  94043, or:
29  *
30  * http://www.sgi.com
31  *
32  * For further information regarding this notice, see:
33  *
34  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
35  */
36 /*
37  * TEST ITEMS
38  *	1. sighold action to turn off the receipt of all signals was done
39  *	   without error.
40  *	2. After signals were held, and sent, no signals were trapped.
41  */
42 #define _XOPEN_SOURCE 500
43 #include <errno.h>
44 #include <signal.h>
45 #include <string.h>
46 #include <fcntl.h>
47 #include <stdlib.h>
48 #include <sys/types.h>
49 #include <sys/wait.h>
50 #include "test.h"
51 #include "safe_macros.h"
52 
53 /* _XOPEN_SOURCE disables NSIG */
54 #ifndef NSIG
55 # define NSIG _NSIG
56 #endif
57 
58 /* Needed for NPTL */
59 #define SIGCANCEL 32
60 #define SIGTIMER 33
61 
62 /* ensure NUMSIGS is defined */
63 #ifndef NUMSIGS
64 # define NUMSIGS NSIG
65 #endif
66 
67 char *TCID = "sighold02";
68 int TST_TOTAL = 2;
69 
70 static int pid;
71 static void do_child(void);
72 static void setup(void);
73 static void cleanup(void);
74 
75 static int sigs_catched;
76 static int sigs_map[NUMSIGS];
77 
skip_sig(int sig)78 static int skip_sig(int sig)
79 {
80 	switch (sig) {
81 	case SIGCHLD:
82 	case SIGKILL:
83 	case SIGALRM:
84 	case SIGSTOP:
85 	case SIGCANCEL:
86 	case SIGTIMER:
87 		return 1;
88 	default:
89 		return 0;
90 	}
91 }
92 
main(int ac,char ** av)93 int main(int ac, char **av)
94 {
95 	int sig;
96 	int lc;
97 
98 	tst_parse_opts(ac, av, NULL, NULL);
99 
100 #ifdef UCLINUX
101 	maybe_run_child(&do_child, "");
102 #endif
103 
104 	setup();
105 
106 	for (lc = 0; TEST_LOOPING(lc); lc++) {
107 		if ((pid = FORK_OR_VFORK()) < 0) {
108 			tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
109 		} else if (pid > 0) {
110 			TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
111 
112 			for (sig = 1; sig < NUMSIGS; sig++) {
113 				if (skip_sig(sig))
114 					continue;
115 				SAFE_KILL(NULL, pid, sig);
116 			}
117 
118 			TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
119 			tst_record_childstatus(cleanup, pid);
120 		} else {
121 
122 #ifdef UCLINUX
123 			if (self_exec(av[0], "") < 0) {
124 				tst_brkm(TBROK | TERRNO, NULL,
125 					 "self_exec() failed");
126 			}
127 #else
128 			do_child();
129 #endif
130 		}
131 	}
132 
133 	cleanup();
134 	tst_exit();
135 }
136 
handle_sigs(int sig)137 static void handle_sigs(int sig)
138 {
139 	sigs_map[sig] = 1;
140 	sigs_catched++;
141 }
142 
do_child(void)143 void do_child(void)
144 {
145 	int cnt;
146 	int sig;
147 
148 	/* set up signal handler routine */
149 	for (sig = 1; sig < NUMSIGS; sig++) {
150 		if (skip_sig(sig))
151 			continue;
152 
153 		if (signal(sig, handle_sigs) == SIG_ERR) {
154 			tst_resm(TBROK | TERRNO, "signal() %i(%s) failed",
155 				 sig, tst_strsig(sig));
156 		}
157 	}
158 
159 	/* all set up to catch signals, now hold them */
160 	for (cnt = 0, sig = 1; sig < NUMSIGS; sig++) {
161 		if (skip_sig(sig))
162 			continue;
163 		cnt++;
164 		TEST(sighold(sig));
165 		if (TEST_RETURN != 0) {
166 			tst_resm(TBROK | TTERRNO, "sighold() %i(%s) failed",
167 				 sig, tst_strsig(sig));
168 		}
169 	}
170 
171 	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
172 
173 	if (!sigs_catched) {
174 		tst_resm(TPASS, "All signals were hold");
175 		tst_exit();
176 	}
177 
178 	tst_resm(TFAIL, "Signal handler was executed");
179 
180 	for (sig = 1; sig < NUMSIGS; sig++) {
181 		if (sigs_map[sig]) {
182 			tst_resm(TINFO, "Signal %i(%s) catched",
183 			         sig, tst_strsig(sig));
184 		}
185 	}
186 
187 	tst_exit();
188 }
189 
setup(void)190 static void setup(void)
191 {
192 	tst_sig(FORK, DEF_HANDLER, NULL);
193 
194 	tst_tmpdir();
195 
196 	TST_CHECKPOINT_INIT(tst_rmdir);
197 
198 	TEST_PAUSE;
199 }
200 
cleanup(void)201 static void cleanup(void)
202 {
203 	tst_rmdir();
204 }
205