]>
Commit | Line | Data |
---|---|---|
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 | 25 | #include "signal-util.h" |
dccca82b | 26 | #include "process-util.h" |
0c5eb056 LP |
27 | |
28 | static void test_block_signals(void) { | |
29 | sigset_t ss; | |
30 | ||
31 | assert_se(sigprocmask(0, NULL, &ss) >= 0); | |
32 | ||
33 | assert_se(sigismember(&ss, SIGUSR1) == 0); | |
34 | assert_se(sigismember(&ss, SIGALRM) == 0); | |
35 | assert_se(sigismember(&ss, SIGVTALRM) == 0); | |
36 | ||
37 | { | |
38 | BLOCK_SIGNALS(SIGUSR1, SIGVTALRM); | |
39 | ||
40 | assert_se(sigprocmask(0, NULL, &ss) >= 0); | |
41 | assert_se(sigismember(&ss, SIGUSR1) == 1); | |
42 | assert_se(sigismember(&ss, SIGALRM) == 0); | |
43 | assert_se(sigismember(&ss, SIGVTALRM) == 1); | |
44 | ||
45 | } | |
46 | ||
47 | assert_se(sigprocmask(0, NULL, &ss) >= 0); | |
48 | assert_se(sigismember(&ss, SIGUSR1) == 0); | |
49 | assert_se(sigismember(&ss, SIGALRM) == 0); | |
50 | assert_se(sigismember(&ss, SIGVTALRM) == 0); | |
51 | } | |
52 | ||
ede4edd3 RC |
53 | static void test_ignore_signals(void) { |
54 | assert_se(ignore_signals(SIGINT, -1) >= 0); | |
df0ff127 | 55 | assert_se(kill(getpid_cached(), SIGINT) >= 0); |
ede4edd3 | 56 | assert_se(ignore_signals(SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0); |
df0ff127 LP |
57 | assert_se(kill(getpid_cached(), SIGUSR1) >= 0); |
58 | assert_se(kill(getpid_cached(), SIGUSR2) >= 0); | |
59 | assert_se(kill(getpid_cached(), SIGTERM) >= 0); | |
60 | assert_se(kill(getpid_cached(), SIGPIPE) >= 0); | |
ede4edd3 RC |
61 | assert_se(default_signals(SIGINT, SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE, -1) >= 0); |
62 | } | |
63 | ||
0c5eb056 LP |
64 | int main(int argc, char *argv[]) { |
65 | test_block_signals(); | |
ede4edd3 RC |
66 | test_ignore_signals(); |
67 | ||
68 | return 0; | |
0c5eb056 | 69 | } |