blob: 1b2c05b991ba8a00201c4356ee7a2a1ec1ee1adf [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * signal03.c
23 *
24 * DESCRIPTION
25 * signal03 - set signals to be ignored
26 *
27 * ALGORITHM
28 * loop if that option was specified
29 * issue the system call
30 * check the return value
31 * if return value == -1
32 * issue a FAIL message, break remaining tests and cleanup
33 * if we are doing functional testing
34 * send the signal with kill()
35 * if we catch the signal
36 * issue a FAIL message
37 * else
38 * issue a PASS message
39 * call cleanup
40 *
41 * USAGE: <for command-line>
42 * signal01 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
43 * where, -c n : Run n copies concurrently.
44 * -f : Turn off functionality Testing.
45 * -i n : Execute test n times.
46 * -I x : Execute test for x seconds.
47 * -P x : Pause for x seconds between iterations.
48 * -t : Turn on syscall timing.
49 *
50 * History
51 * 07/2001 John George
52 * -Ported
53 *
54 * Restrictions
55 * none
56 */
57
58#include "test.h"
plars865695b2001-08-27 22:15:12 +000059
60#include <errno.h>
61#include <signal.h>
62
63void cleanup(void);
64void setup(void);
65void sighandler(int);
66
plars865695b2001-08-27 22:15:12 +000067int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
subrata_modak56207ce2009-03-23 13:35:39 +000068 SIGBUS, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM,
69 SIGTERM,
plars067f3842002-05-28 14:45:38 +000070#ifdef SIGSTKFLT
subrata_modak56207ce2009-03-23 13:35:39 +000071 SIGSTKFLT,
plars067f3842002-05-28 14:45:38 +000072#endif
subrata_modak56207ce2009-03-23 13:35:39 +000073 SIGCHLD, SIGCONT, SIGTSTP, SIGTTIN,
74 SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF,
75 SIGWINCH, SIGIO, SIGPWR, SIGSYS,
plars067f3842002-05-28 14:45:38 +000076#ifdef SIGUNUSED
subrata_modak56207ce2009-03-23 13:35:39 +000077 SIGUNUSED
plars067f3842002-05-28 14:45:38 +000078#endif
79};
plars865695b2001-08-27 22:15:12 +000080
Cyril Hrubis63564ce2015-02-04 13:28:31 +010081char *TCID = "signal03";
82int TST_TOTAL = ARRAY_SIZE(siglist);
83
84typedef void (*sighandler_t) (int);
85
86sighandler_t Tret;
87
88int fail = 0;
89
plars74948ad2002-11-14 16:16:14 +000090int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000091{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020092 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020093 const char *msg;
plars865695b2001-08-27 22:15:12 +000094 pid_t pid;
95 int i, rval;
96
Garrett Cooper45e285d2010-11-22 12:19:25 -080097 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080098 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +080099 }
plars865695b2001-08-27 22:15:12 +0000100
subrata_modak56207ce2009-03-23 13:35:39 +0000101 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +0000102
103 /* The following loop checks looping state if -i option given */
104
105 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800106 /* reset tst_count in case we are looping */
107 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000108
109 /*
110 * loop through the list of signals and test each one
111 */
subrata_modak56207ce2009-03-23 13:35:39 +0000112 for (i = 0; i < TST_TOTAL; i++) {
plars865695b2001-08-27 22:15:12 +0000113
subrata_modak56207ce2009-03-23 13:35:39 +0000114 errno = 0;
115 Tret = signal(siglist[i], SIG_IGN);
116 TEST_ERRNO = errno;
plars865695b2001-08-27 22:15:12 +0000117
subrata_modak56207ce2009-03-23 13:35:39 +0000118 if (Tret == SIG_ERR) {
plars865695b2001-08-27 22:15:12 +0000119 tst_brkm(TFAIL, cleanup, "%s call failed - "
120 "errno = %d : %s", TCID,
121 TEST_ERRNO, strerror(TEST_ERRNO));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800122 }
plars865695b2001-08-27 22:15:12 +0000123
Cyril Hrubise38b9612014-06-02 17:20:57 +0200124 /*
125 * Send the signal. If the signal is truly set
126 * to be ignored, then the signal handler will
127 * never be invoked and the test will pass.
128 */
129 pid = getpid();
plars865695b2001-08-27 22:15:12 +0000130
Cyril Hrubise38b9612014-06-02 17:20:57 +0200131 if ((rval = kill(pid, siglist[i])) != 0) {
132 tst_brkm(TBROK, cleanup, "call to "
133 "kill failed");
134 }
plars865695b2001-08-27 22:15:12 +0000135
Cyril Hrubise38b9612014-06-02 17:20:57 +0200136 if (fail == 0) {
137 tst_resm(TPASS, "%s call succeeded",
138 TCID);
plars865695b2001-08-27 22:15:12 +0000139 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200140 /* the signal was caught so we fail */
141 tst_resm(TFAIL, "signal caught when "
142 "suppose to be ignored");
plars865695b2001-08-27 22:15:12 +0000143 }
144 }
145 }
146
147 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800148 tst_exit();
plars865695b2001-08-27 22:15:12 +0000149}
150
151/*
152 * sighandler() - the test fails if we ever get here.
153 */
subrata_modak56207ce2009-03-23 13:35:39 +0000154void sighandler(int sig)
plars865695b2001-08-27 22:15:12 +0000155{
156 fail = 1;
157}
158
159/*
160 * setup() - performs all the ONE TIME setup for this test.
161 */
subrata_modak56207ce2009-03-23 13:35:39 +0000162void setup(void)
plars865695b2001-08-27 22:15:12 +0000163{
plars865695b2001-08-27 22:15:12 +0000164 /* capture signals in our own handler */
165 tst_sig(NOFORK, sighandler, cleanup);
166
plars865695b2001-08-27 22:15:12 +0000167 TEST_PAUSE;
168}
169
170/*
171 * cleanup() - performs all the ONE TIME cleanup for this test at completion
172 * or premature exit.
173 */
subrata_modak56207ce2009-03-23 13:35:39 +0000174void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000175{
plars865695b2001-08-27 22:15:12 +0000176
Chris Dearmanec6edca2012-10-17 19:54:01 -0700177}