xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/signal/signal05.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  * Set the signal handler to our own function.
10  */
11 
12 #include "tst_test.h"
13 
14 static int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
15 	SIGBUS, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM,
16 	SIGTERM,
17 #ifdef SIGSTKFLT
18 	SIGSTKFLT,
19 #endif
20 	SIGCHLD, SIGCONT, SIGTSTP, SIGTTIN,
21 	SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF,
22 	SIGWINCH, SIGIO, SIGPWR, SIGSYS,
23 #ifdef SIGUNUSED
24 	SIGUNUSED
25 #endif
26 };
27 
28 static volatile int sig_pass;
29 
sighandler(int sig)30 static void sighandler(int sig)
31 {
32 	sig_pass = sig;
33 }
34 
do_test(unsigned int n)35 static void do_test(unsigned int n)
36 {
37 	pid_t pid;
38 
39 	SAFE_SIGNAL(siglist[n], sighandler);
40 
41 	pid = getpid();
42 
43 	SAFE_KILL(pid, siglist[n]);
44 	TST_EXP_EQ_SSZ(siglist[n], sig_pass);
45 }
46 
47 static struct tst_test test = {
48 	.tcnt = ARRAY_SIZE(siglist),
49 	.test = do_test,
50 };
51