]> granicus.if.org Git - strace/blob - tests/block_reset_raise_run.c
dfa92fd1ff53a2f2c9ac11f7c356be1bdd7b2771
[strace] / tests / block_reset_raise_run.c
1 /*
2  * Execute a command with blocked, reset, and raised signal.
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 < 3)
19                 error_msg_and_fail("usage: block_reset_raise_run signo path...");
20
21         sigset_t mask;
22         sigemptyset(&mask);
23         const int signo = atoi(av[1]);
24         if (sigaddset(&mask, signo))
25                 perror_msg_and_fail("sigaddset: %s", av[1]);
26         if (sigprocmask(SIG_BLOCK, &mask, NULL))
27                 perror_msg_and_fail("sigprocmask");
28         if (signal(signo, SIG_DFL) == SIG_ERR)
29                 perror_msg_and_fail("signal: %s", av[1]);
30         if (raise(signo))
31                 perror_msg_and_fail("raise: %s", av[1]);
32
33         execvp(av[2], av + 2);
34         perror_msg_and_fail("execvp: %s", av[2]);
35 }