]> granicus.if.org Git - strace/blob - tests/inotify_init1.c
strace: terminate itself if interrupted by a signal
[strace] / tests / inotify_init1.c
1 /*
2  * Check decoding of inotify_init1 syscall.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11
12 #include <asm/unistd.h>
13
14 #if defined(__NR_inotify_init1)
15
16 # include <fcntl.h>
17 # include <stdio.h>
18 # include <unistd.h>
19
20 # ifdef O_CLOEXEC
21 #  define cloexec_flag O_CLOEXEC
22 # else
23 #  define cloexec_flag 0
24 # endif
25 # define all_flags (O_NONBLOCK | cloexec_flag)
26
27 int
28 main(void)
29 {
30         static const kernel_ulong_t bogus_flags1 =
31                 (kernel_ulong_t) 0xfacefeeddeadbeefULL | O_NONBLOCK;
32         static const kernel_ulong_t bogus_flags2 =
33                 (kernel_ulong_t) 0x55555550ff96b77bULL & ~all_flags;
34
35         long rc;
36
37         rc = syscall(__NR_inotify_init1, bogus_flags1);
38         printf("inotify_init1(IN_NONBLOCK|%s%#x) = %s\n",
39                bogus_flags1 & cloexec_flag  ? "IN_CLOEXEC|" : "",
40                (unsigned int) (bogus_flags1 & ~all_flags),
41                sprintrc(rc));
42
43         rc = syscall(__NR_inotify_init1, bogus_flags2);
44         printf("inotify_init1(%#x /* IN_??? */) = %s\n",
45                (unsigned int) bogus_flags2, sprintrc(rc));
46
47         rc = syscall(__NR_inotify_init1, all_flags);
48         printf("inotify_init1(IN_NONBLOCK%s) = %s\n",
49                all_flags & cloexec_flag ? "|IN_CLOEXEC" : "", sprintrc(rc));
50
51         puts("+++ exited with 0 +++");
52
53         return 0;
54 }
55
56 #else
57
58 SKIP_MAIN_UNDEFINED("__NR_inotify_init1");
59
60 #endif