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