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