]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-signal-util.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / test / test-signal-util.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
0c5eb056
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2016 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
ede4edd3
RC
21#include <signal.h>
22#include <unistd.h>
23
24#include "macro.h"
0c5eb056
LP
25#include "signal-util.h"
26
27static void test_block_signals(void) {
28 sigset_t ss;
29
30 assert_se(sigprocmask(0, NULL, &ss) >= 0);
31
32 assert_se(sigismember(&ss, SIGUSR1) == 0);
33 assert_se(sigismember(&ss, SIGALRM) == 0);
34 assert_se(sigismember(&ss, SIGVTALRM) == 0);
35
36 {
37 BLOCK_SIGNALS(SIGUSR1, SIGVTALRM);
38
39 assert_se(sigprocmask(0, NULL, &ss) >= 0);
40 assert_se(sigismember(&ss, SIGUSR1) == 1);
41 assert_se(sigismember(&ss, SIGALRM) == 0);
42 assert_se(sigismember(&ss, SIGVTALRM) == 1);
43
44 }
45
46 assert_se(sigprocmask(0, NULL, &ss) >= 0);
47 assert_se(sigismember(&ss, SIGUSR1) == 0);
48 assert_se(sigismember(&ss, SIGALRM) == 0);
49 assert_se(sigismember(&ss, SIGVTALRM) == 0);
50}
51
ede4edd3
RC
52static void test_ignore_signals(void) {
53 assert_se(ignore_signals(SIGINT, -1) >= 0);
df0ff127 54 assert_se(kill(getpid_cached(), SIGINT) >= 0);
ede4edd3 55 assert_se(ignore_signals(SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
df0ff127
LP
56 assert_se(kill(getpid_cached(), SIGUSR1) >= 0);
57 assert_se(kill(getpid_cached(), SIGUSR2) >= 0);
58 assert_se(kill(getpid_cached(), SIGTERM) >= 0);
59 assert_se(kill(getpid_cached(), SIGPIPE) >= 0);
ede4edd3
RC
60 assert_se(default_signals(SIGINT, SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0);
61}
62
0c5eb056
LP
63int main(int argc, char *argv[]) {
64 test_block_signals();
ede4edd3
RC
65 test_ignore_signals();
66
67 return 0;
0c5eb056 68}