1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * AUTHOR : Bob Clark
5 * CO-PILOT : Barrie Kletscher
6 * DATE STARTED : 9/26/86
7 * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
8 * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
9 */
10
11 /*\
12 * [Description]
13 *
14 * This test checks following conditions:
15 * 1. sighold action to turn off the receipt of all signals was done without error.
16 * 2. After signals were held, and sent, no signals were trapped.
17 */
18
19 #define _XOPEN_SOURCE 600
20 #include <signal.h>
21 #include "tst_test.h"
22
23 #ifndef NSIG
24 # define NSIG _NSIG
25 #endif
26
27 #ifndef NUMSIGS
28 # define NUMSIGS NSIG
29 #endif
30
31 static int sigs_catched;
32 static int sigs_map[NUMSIGS];
33
skip_sig(int sig)34 static int skip_sig(int sig)
35 {
36 if (sig >= 32 && sig < SIGRTMIN)
37 return 1;
38
39 switch (sig) {
40 case SIGCHLD:
41 case SIGKILL:
42 case SIGALRM:
43 case SIGSTOP:
44 return 1;
45 default:
46 return 0;
47 }
48 }
49
handle_sigs(int sig)50 static void handle_sigs(int sig)
51 {
52 sigs_map[sig] = 1;
53 sigs_catched++;
54 }
55
do_child(void)56 static void do_child(void)
57 {
58 int sig;
59
60 for (sig = 1; sig < NUMSIGS; sig++) {
61 if (skip_sig(sig))
62 continue;
63
64 SAFE_SIGNAL(sig, handle_sigs);
65 }
66
67 for (sig = 1; sig < NUMSIGS; sig++) {
68 if (skip_sig(sig))
69 continue;
70
71 if (sighold(sig))
72 tst_brk(TBROK | TERRNO, "sighold(%s %i)", tst_strsig(sig), sig);
73 }
74
75 TST_CHECKPOINT_WAKE_AND_WAIT(0);
76
77 if (!sigs_catched) {
78 tst_res(TPASS, "all signals were hold");
79 return;
80 }
81
82 tst_res(TFAIL, "signal handler was executed");
83
84 for (sig = 1; sig < NUMSIGS; sig++)
85 if (sigs_map[sig])
86 tst_res(TINFO, "Signal %i(%s) catched", sig, tst_strsig(sig));
87 }
88
run(void)89 static void run(void)
90 {
91 pid_t pid_child;
92 int signal;
93
94 pid_child = SAFE_FORK();
95 if (!pid_child) {
96 do_child();
97 return;
98 }
99
100 TST_CHECKPOINT_WAIT(0);
101
102 for (signal = 1; signal < NUMSIGS; signal++) {
103 if (skip_sig(signal))
104 continue;
105
106 SAFE_KILL(pid_child, signal);
107 }
108
109 TST_CHECKPOINT_WAKE(0);
110 }
111
112 static struct tst_test test = {
113 .test_all = run,
114 .forks_child = 1,
115 .needs_checkpoints = 1,
116 };
117