xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/signal/signal04.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker  *
9*49cdfc7eSAndroid Build Coastguard Worker  * Restore signals to default behavior.
10*49cdfc7eSAndroid Build Coastguard Worker  */
11*49cdfc7eSAndroid Build Coastguard Worker 
12*49cdfc7eSAndroid Build Coastguard Worker #include "signal.h"
13*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
14*49cdfc7eSAndroid Build Coastguard Worker 
15*49cdfc7eSAndroid Build Coastguard Worker static int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
16*49cdfc7eSAndroid Build Coastguard Worker 	SIGBUS, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM,
17*49cdfc7eSAndroid Build Coastguard Worker 	SIGTERM, SIGCHLD, SIGCONT, SIGTSTP, SIGTTIN,
18*49cdfc7eSAndroid Build Coastguard Worker 	SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF,
19*49cdfc7eSAndroid Build Coastguard Worker 	SIGWINCH, SIGIO, SIGPWR, SIGSYS
20*49cdfc7eSAndroid Build Coastguard Worker };
21*49cdfc7eSAndroid Build Coastguard Worker 
sighandler(int sig LTP_ATTRIBUTE_UNUSED)22*49cdfc7eSAndroid Build Coastguard Worker static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
23*49cdfc7eSAndroid Build Coastguard Worker {
24*49cdfc7eSAndroid Build Coastguard Worker }
25*49cdfc7eSAndroid Build Coastguard Worker 
do_test(unsigned int n)26*49cdfc7eSAndroid Build Coastguard Worker static void do_test(unsigned int n)
27*49cdfc7eSAndroid Build Coastguard Worker {
28*49cdfc7eSAndroid Build Coastguard Worker 	sighandler_t rval, first;
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_SIGNAL(siglist[n], SIG_DFL);
31*49cdfc7eSAndroid Build Coastguard Worker 	first = SAFE_SIGNAL(siglist[n], sighandler);
32*49cdfc7eSAndroid Build Coastguard Worker 
33*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_SIGNAL(siglist[n], SIG_DFL);
34*49cdfc7eSAndroid Build Coastguard Worker 	rval = SAFE_SIGNAL(siglist[n], sighandler);
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker 	if (rval == first) {
37*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TPASS, "signal(%d) restore succeeded "
38*49cdfc7eSAndroid Build Coastguard Worker 				"received %p.", siglist[n], rval);
39*49cdfc7eSAndroid Build Coastguard Worker 	} else {
40*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TFAIL, "return values for signal(%d) don't match. "
41*49cdfc7eSAndroid Build Coastguard Worker 				"Got %p, expected %p.",
42*49cdfc7eSAndroid Build Coastguard Worker 				siglist[n], rval, first);
43*49cdfc7eSAndroid Build Coastguard Worker 	}
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker 
46*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
47*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(siglist),
48*49cdfc7eSAndroid Build Coastguard Worker 	.test = do_test,
49*49cdfc7eSAndroid Build Coastguard Worker };
50