Browse Source

inotify: decode file descriptor returned by inotify_init

* inotify.c (SYS_FUNC(inotify_init)): New function.
* linux/dummy.h (sys_inotify_init): Remove macro definition.
* tests/inotify_init.c: New file.
* tests/inotify_init-y.c: Likewise.
* tests/inotify_init1-y.c: Likewise.
* tests/inotify_init1.c [PRINT_PATHS]: Print inotify fd path.
* tests/inotify_init-y.test: New test.
* tests/.gitignore: Add inotify_init, inotify_init-y, inotify_init1-y.
* tests/pure_executables.list: Likewise.
* tests/gen_tests.in (inotify_init, inotify_init1-y): New tests.
* tests/Makefile.am (DECODER_TESTS): Add inotify_init-y.test.
Eugene Syromyatnikov 1 year ago
parent
commit
879bc9caac

+ 5
- 0
inotify.c View File

@@ -36,6 +36,11 @@ SYS_FUNC(inotify_rm_watch)
36 36
 	return RVAL_DECODED;
37 37
 }
38 38
 
39
+SYS_FUNC(inotify_init)
40
+{
41
+	return RVAL_DECODED | RVAL_FD;
42
+}
43
+
39 44
 SYS_FUNC(inotify_init1)
40 45
 {
41 46
 	printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");

+ 0
- 1
linux/dummy.h View File

@@ -92,7 +92,6 @@
92 92
 # define sys_getppid		printargs
93 93
 # define sys_gettid		printargs
94 94
 # define sys_idle		printargs
95
-# define sys_inotify_init	printargs
96 95
 # define sys_munlockall		printargs
97 96
 # define sys_pause		printargs
98 97
 # define sys_printargs		printargs

+ 3
- 0
tests/.gitignore View File

@@ -148,7 +148,10 @@ inet-cmsg
148 148
 init_module
149 149
 inject-nf
150 150
 inotify
151
+inotify_init
152
+inotify_init-y
151 153
 inotify_init1
154
+inotify_init1-y
152 155
 int_0x80
153 156
 io_uring_enter
154 157
 io_uring_register

+ 1
- 0
tests/Makefile.am View File

@@ -234,6 +234,7 @@ DECODER_TESTS = \
234 234
 	futex.test \
235 235
 	getuid.test \
236 236
 	int_0x80.test \
237
+	inotify_init-y.test \
237 238
 	ioctl.test \
238 239
 	ioctl_evdev-success-v.test \
239 240
 	ioctl_evdev-success.test \

+ 2
- 0
tests/gen_tests.in View File

@@ -123,7 +123,9 @@ group_req	-e trace=setsockopt
123 123
 inet-cmsg	-e trace=recvmsg
124 124
 init_module	-a27
125 125
 inotify	-a23 -e trace=inotify_add_watch,inotify_rm_watch
126
+inotify_init	-a15
126 127
 inotify_init1	-a27
128
+inotify_init1-y	-a27 -y -e trace=inotify_init1
127 129
 io_uring_enter	-y
128 130
 io_uring_register	-y
129 131
 io_uring_setup	-a26 -y

+ 2
- 0
tests/inotify_init-y.c View File

@@ -0,0 +1,2 @@
1
+#define PRINT_PATHS
2
+#include "inotify_init.c"

+ 17
- 0
tests/inotify_init-y.test View File

@@ -0,0 +1,17 @@
1
+#!/bin/sh
2
+#
3
+# Check decoding of inotify_init with path decoding enabled.
4
+#
5
+# Copyright (c) 2019 The strace developers.
6
+# All rights reserved.
7
+#
8
+# SPDX-License-Identifier: GPL-2.0-or-later
9
+
10
+. "${srcdir=.}/init.sh"
11
+
12
+# Test expects "anon_inode:inotify" link path format for a inotify fd, which
13
+# is in place since v2.6.33-rc1~34^2~7. Check for older link path formats
14
+# is implemented in inotify_init1 test.
15
+require_min_kernel_version_or_skip 2.6.33
16
+
17
+run_strace_match_diff -a15 -y -e trace=inotify_init

+ 49
- 0
tests/inotify_init.c View File

@@ -0,0 +1,49 @@
1
+/*
2
+ * Check decoding of inotify_init syscall.
3
+ *
4
+ * Copyright (c) 2018-2019 The strace developers.
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
+#include "scno.h"
13
+
14
+#ifdef __NR_inotify_init
15
+
16
+# include <stdio.h>
17
+# include <unistd.h>
18
+
19
+int
20
+main(void)
21
+{
22
+#ifdef PRINT_PATHS
23
+	skip_if_unavailable("/proc/self/fd/");
24
+#endif
25
+
26
+	long rc = syscall(__NR_inotify_init, 42);
27
+
28
+#ifdef PRINT_PATHS
29
+	if (rc < 0)
30
+		perror_msg_and_skip("inotify_init");
31
+#endif
32
+
33
+	printf("inotify_init() = "
34
+#ifdef PRINT_PATHS
35
+	       "%ld<anon_inode:inotify>\n", rc
36
+#else
37
+	       "%s\n", sprintrc(rc)
38
+#endif
39
+	       );
40
+
41
+	puts("+++ exited with 0 +++");
42
+	return 0;
43
+}
44
+
45
+#else
46
+
47
+SKIP_MAIN_UNDEFINED("__NR_inotify_init");
48
+
49
+#endif

+ 2
- 0
tests/inotify_init1-y.c View File

@@ -0,0 +1,2 @@
1
+#define PRINT_PATHS
2
+#include "inotify_init1.c"

+ 55
- 2
tests/inotify_init1.c View File

@@ -25,9 +25,19 @@
25 25
 # endif
26 26
 # define all_flags (O_NONBLOCK | cloexec_flag)
27 27
 
28
+#ifdef PRINT_PATHS
29
+# define RC_FMT "%ld<%s>"
30
+#else
31
+# define RC_FMT "%s"
32
+#endif
33
+
28 34
 int
29 35
 main(void)
30 36
 {
37
+#ifdef PRINT_PATHS
38
+	skip_if_unavailable("/proc/self/fd/");
39
+#endif
40
+
31 41
 	static const kernel_ulong_t bogus_flags1 =
32 42
 		(kernel_ulong_t) 0xfacefeeddeadbeefULL | O_NONBLOCK;
33 43
 	static const kernel_ulong_t bogus_flags2 =
@@ -46,8 +56,51 @@ main(void)
46 56
 	       (unsigned int) bogus_flags2, sprintrc(rc));
47 57
 
48 58
 	rc = syscall(__NR_inotify_init1, all_flags);
49
-	printf("inotify_init1(IN_NONBLOCK%s) = %s\n",
50
-	       all_flags & cloexec_flag ? "|IN_CLOEXEC" : "", sprintrc(rc));
59
+
60
+#ifdef PRINT_PATHS
61
+	if (rc < 0)
62
+		perror_msg_and_skip("inotify_init(%#x)", all_flags);
63
+
64
+	/*
65
+	 * Kernels that do not have v2.6.33-rc1~34^2~7 do not have
66
+	 * "anon_inode:" prefix.  Let's assume that it can be either "inotify"
67
+	 * or "anon_inode:inotify" for now, as any change there may be
68
+	 * of interest.
69
+	 */
70
+	char path[sizeof("/proc/self/fd/") + sizeof(rc) * 3];
71
+	char buf[2] = "";
72
+	const char *inotify_path;
73
+	ssize_t ret;
74
+
75
+	ret = snprintf(path, sizeof(path), "/proc/self/fd/%ld", rc);
76
+	if ((ret < 0) || ((size_t) ret >= sizeof(path)))
77
+		perror_msg_and_fail("snprintf(path)");
78
+
79
+	ret = readlink(path, buf, sizeof(buf));
80
+	if (ret < 0)
81
+		perror_msg_and_fail("readlink");
82
+
83
+	switch (buf[0]) {
84
+	case 'a':
85
+		inotify_path = "anon_inode:inotify";
86
+		break;
87
+	case 'i':
88
+		inotify_path = "inotify";
89
+		break;
90
+	default:
91
+		error_msg_and_fail("Unexpected first char '%c' of inotify fd "
92
+				   "link path", buf[0]);
93
+	}
94
+#endif
95
+
96
+	printf("inotify_init1(IN_NONBLOCK%s) = " RC_FMT "\n",
97
+	       all_flags & cloexec_flag ? "|IN_CLOEXEC" : "",
98
+#ifdef PRINT_PATHS
99
+	       rc, inotify_path
100
+#else
101
+	       sprintrc(rc)
102
+#endif
103
+	       );
51 104
 
52 105
 	puts("+++ exited with 0 +++");
53 106
 

+ 3
- 0
tests/pure_executables.list View File

@@ -126,7 +126,10 @@ group_req
126 126
 inet-cmsg
127 127
 init_module
128 128
 inotify
129
+inotify_init
130
+inotify_init-y
129 131
 inotify_init1
132
+inotify_init1-y
130 133
 io_uring_enter
131 134
 io_uring_register
132 135
 io_uring_setup

Loading…
Cancel
Save