]> granicus.if.org Git - strace/blob - tests/set_sigblock.c
tests: change the license to GPL-2.0-or-later
[strace] / tests / set_sigblock.c
1 /*
2  * Execute a command with the specified signal blocked/unblocked.
3  *
4  * Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11 #include <signal.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 int
16 main(int ac, char **av)
17 {
18         if (ac < 4)
19                 error_msg_and_fail("usage: set_sigblock 0|1 signum path...");
20
21         const int block = atoi(av[1]);
22         const int signum = atoi(av[2]);
23         sigset_t mask;
24
25         sigemptyset(&mask);
26         if (sigaddset(&mask, signum))
27                 perror_msg_and_fail("sigaddset: %s", av[2]);
28         if (sigprocmask(block ? SIG_BLOCK : SIG_UNBLOCK, &mask, NULL))
29                 perror_msg_and_fail("sigprocmask");
30
31         execvp(av[3], av + 3);
32         perror_msg_and_fail("execvp: %s", av[3]);
33 }