]> granicus.if.org Git - strace/blob - tests/qual_inject-error-signal.c
tests: change the license to GPL-2.0-or-later
[strace] / tests / qual_inject-error-signal.c
1 /*
2  * Check fault injection along with signal injection.
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 <unistd.h>
13 #include <sys/stat.h>
14 #include <asm/unistd.h>
15
16 static struct stat before, after;
17
18 static void
19 handler(int sig)
20 {
21         if (stat(".", &after))
22                 syscall(__NR_exit_group, 2);
23
24         if (before.st_dev != after.st_dev || before.st_ino != after.st_ino)
25                 syscall(__NR_exit_group, 3);
26
27         syscall(__NR_exit_group, 0);
28 }
29
30 int
31 main(void)
32 {
33         const struct sigaction act = { .sa_handler = handler };
34         if (sigaction(SIGUSR1, &act, NULL))
35                 perror_msg_and_fail("sigaction");
36
37         sigset_t mask;
38         sigemptyset(&mask);
39         sigaddset(&mask, SIGUSR1);
40         if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
41                 perror_msg_and_fail("sigprocmask");
42
43         if (stat(".", &before))
44                 perror_msg_and_fail("stat");
45
46         syscall(__NR_chdir, ".");
47         syscall(__NR_exit_group, 1);
48         return 1;
49 }