1 /*
2 * Execute a command, expect its termination with a specified signal.
3 *
4 * Copyright (c) 2017-2021 Dmitry V. Levin <ldv@strace.io>
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 #include <sys/wait.h>
15
16 int
17 main(int ac, char **av)
18 {
19 if (ac < 3)
20 error_msg_and_fail("usage: run_expect_termsig signo path...");
21
22 signal(SIGCHLD, SIG_DFL);
23
24 pid_t pid = fork();
25 if (pid < 0)
26 perror_msg_and_fail("fork");
27
28 if (!pid) {
29 execvp(av[2], av + 2);
30 perror_msg_and_fail("execvp: %s", av[2]);
31 }
32
33 int status;
34 if (waitpid(pid, &status, 0) != pid)
35 perror_msg_and_fail("waitpid");
36
37 return !(WIFSIGNALED(status) && WTERMSIG(status) == atoi(av[1]));
38 }