]> granicus.if.org Git - strace/blob - tests/kill.c
strace: terminate itself if interrupted by a signal
[strace] / tests / kill.c
1 /*
2  * Check decoding of kill syscall.
3  *
4  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2016 Fei Jie <feij.fnst@cn.fujitsu.com>
6  * All rights reserved.
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "tests.h"
12 #include <asm/unistd.h>
13
14 #ifdef __NR_kill
15
16 # include <signal.h>
17 # include <stdio.h>
18 # include <unistd.h>
19
20 static void
21 handler(int sig)
22 {
23 }
24
25 int
26 main(void)
27 {
28         const struct sigaction act = { .sa_handler = handler };
29         if (sigaction(SIGALRM, &act, NULL))
30                 perror_msg_and_fail("sigaction");
31
32         sigset_t mask;
33         sigemptyset(&mask);
34         sigaddset(&mask, SIGALRM);
35         if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
36                 perror_msg_and_fail("sigprocmask");
37
38         const int pid = getpid();
39         long rc = syscall(__NR_kill, pid, (long) 0xdefaced00000000ULL | SIGALRM);
40         printf("kill(%d, SIGALRM) = %ld\n", pid, rc);
41
42         const long big_pid = (long) 0xfacefeedbadc0dedULL;
43         const long big_sig = (long) 0xdeadbeefcafef00dULL;
44         rc = syscall(__NR_kill, big_pid, big_sig);
45         printf("kill(%d, %d) = %ld %s (%m)\n",
46                (int) big_pid, (int) big_sig, rc, errno2name());
47
48         rc = syscall(__NR_kill, (long) 0xdefaced00000000ULL | pid, 0);
49         printf("kill(%d, 0) = %ld\n", pid, rc);
50
51         puts("+++ exited with 0 +++");
52         return 0;
53 }
54
55 #else
56
57 SKIP_MAIN_UNDEFINED("__NR_kill")
58
59 #endif