Commit 55f5bd3
authored
libbpf-tools: statsnoop: Support fstat(2) and parse fd/dirfd in userspace (#5233)
Added support for fstat system calls, and resolve file names and paths from fd
and dirfd in user mode.
Userspace test code:
# fstatat.c
dirfd = openat(AT_FDCWD, "./", O_RDONLY | O_CLOEXEC);
fstatat(dirfd, argv[0], &buf, AT_SYMLINK_NOFOLLOW);
fstatat(dirfd, "/etc/os-release", &buf, AT_SYMLINK_NOFOLLOW);
# fstat.c
fd = open("/etc/os-release", O_RDONLY);
fstat(fd, &buf);
fstat(AT_FDCWD, &buf);
Tracing:
Before:
$ sudo ./statsnoop -s
PID COMM RET ERR SYSCALL PATH
25719 fstatat 0 0 newfstatat ./fstatat <no cwd>
25719 fstatat 0 0 newfstatat /etc/os-release
< couldn't tracing fstat(2) >
This patch:
$ sudo ./statsnoop -s
PID COMM RET ERR SYSCALL PATH
26794 fstatat 0 0 newfstatat /home/sdb/Git/tst-linux/syscall/samples/stat/./fstatat
26794 fstatat 0 0 newfstatat /etc/os-release
26797 fstat 0 0 newfstat /usr/lib/os-release
26800 fstat -1 9 newfstat /home/sdb/Git/tst-linux/syscall/samples/stat
Maybe this isn't a good approach, as it's possible that both the process and
the fd don't exist during parsing the fd and dirfd. Of course, this is
problematic for processes and fds that survive for a short period of time,
however, for long-running daemons, there is no problem.
Signed-off-by: Rong Tao <[email protected]>1 parent db5b63f commit 55f5bd3
3 files changed
+91
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | | - | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | | - | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| |||
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
73 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
| |||
80 | 91 | | |
81 | 92 | | |
82 | 93 | | |
83 | | - | |
| 94 | + | |
| 95 | + | |
84 | 96 | | |
85 | 97 | | |
86 | 98 | | |
| |||
92 | 104 | | |
93 | 105 | | |
94 | 106 | | |
95 | | - | |
| 107 | + | |
| 108 | + | |
96 | 109 | | |
97 | 110 | | |
98 | 111 | | |
| |||
104 | 117 | | |
105 | 118 | | |
106 | 119 | | |
107 | | - | |
| 120 | + | |
| 121 | + | |
108 | 122 | | |
109 | 123 | | |
110 | 124 | | |
| |||
113 | 127 | | |
114 | 128 | | |
115 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
116 | 144 | | |
117 | 145 | | |
118 | 146 | | |
119 | | - | |
| 147 | + | |
| 148 | + | |
120 | 149 | | |
121 | 150 | | |
122 | 151 | | |
| |||
128 | 157 | | |
129 | 158 | | |
130 | 159 | | |
131 | | - | |
| 160 | + | |
| 161 | + | |
132 | 162 | | |
133 | 163 | | |
134 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| |||
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
112 | 146 | | |
113 | 147 | | |
114 | 148 | | |
115 | 149 | | |
116 | 150 | | |
117 | 151 | | |
| 152 | + | |
118 | 153 | | |
119 | 154 | | |
120 | 155 | | |
| |||
139 | 174 | | |
140 | 175 | | |
141 | 176 | | |
142 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
143 | 182 | | |
144 | 183 | | |
145 | 184 | | |
| |||
196 | 235 | | |
197 | 236 | | |
198 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
199 | 242 | | |
200 | 243 | | |
201 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
22 | 31 | | |
23 | 32 | | |
24 | 33 | | |
| |||
0 commit comments