]> granicus.if.org Git - strace/blob - tests/pipe2.c
strace: terminate itself if interrupted by a signal
[strace] / tests / pipe2.c
1 /*
2  * Check decoding of pipe2 syscall.
3  *
4  * Copyright (c) 2015-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 <asm/unistd.h>
12
13 #ifdef __NR_pipe2
14
15 # include <fcntl.h>
16 # include <stdio.h>
17 # include <unistd.h>
18
19 int
20 main(void)
21 {
22         int *const fds = tail_alloc(sizeof(*fds) * 2);
23         int *const efault = fds + 1;
24         long rc;
25
26         rc = syscall(__NR_pipe2, fds, F8ILL_KULONG_MASK | O_NONBLOCK);
27         if (rc)
28                 perror_msg_and_skip("pipe2");
29         printf("pipe2([%d, %d], O_NONBLOCK) = 0\n", fds[0], fds[1]);
30
31         rc = syscall(__NR_pipe2, efault, F8ILL_KULONG_MASK);
32         printf("pipe2(%p, 0) = %s\n", efault, sprintrc(rc));
33
34         if (F8ILL_KULONG_SUPPORTED) {
35                 const kernel_ulong_t ill = f8ill_ptr_to_kulong(fds);
36                 rc = syscall(__NR_pipe2, ill, 0);
37                 printf("pipe2(%#llx, 0) = %s\n",
38                        (unsigned long long) ill, sprintrc(rc));
39         }
40
41         puts("+++ exited with 0 +++");
42         return 0;
43 }
44
45 #else
46
47 SKIP_MAIN_UNDEFINED("__NR_pipe2")
48
49 #endif