diff options
author | Quentin Monnet <quentin.monnet@netronome.com> | 2018-11-30 11:25:44 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-11-30 17:06:06 -0500 |
commit | 327e5dab6dd8559ba28739ec8873350d7b5bb080 (patch) | |
tree | 370cef3a25e60fa348730d04ee1561b7f726d705 | |
parent | cc2b8ed1369592fb84609e920f99a5659a6445f7 (diff) |
tools: bpftool: use "/proc/self/" i.o. crafting links with getpid()
The getpid() function is called in a couple of places in bpftool to
craft links of the shape "/proc/<pid>/...". Instead, it is possible to
use the "/proc/self/" shortcut, which makes things a bit easier, in
particular in jit_disasm.c.
Do the replacement, and remove the includes of <sys/types.h> from the
relevant files, now we do not use getpid() anymore.
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/bpf/bpftool/common.c | 5 | ||||
-rw-r--r-- | tools/bpf/bpftool/jit_disasm.c | 11 |
2 files changed, 3 insertions, 13 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index 4e217d57118e..4349b6683ca8 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c | |||
@@ -48,7 +48,6 @@ | |||
48 | #include <sys/mount.h> | 48 | #include <sys/mount.h> |
49 | #include <sys/resource.h> | 49 | #include <sys/resource.h> |
50 | #include <sys/stat.h> | 50 | #include <sys/stat.h> |
51 | #include <sys/types.h> | ||
52 | #include <sys/vfs.h> | 51 | #include <sys/vfs.h> |
53 | 52 | ||
54 | #include <bpf.h> | 53 | #include <bpf.h> |
@@ -276,7 +275,7 @@ int get_fd_type(int fd) | |||
276 | char buf[512]; | 275 | char buf[512]; |
277 | ssize_t n; | 276 | ssize_t n; |
278 | 277 | ||
279 | snprintf(path, sizeof(path), "/proc/%d/fd/%d", getpid(), fd); | 278 | snprintf(path, sizeof(path), "/proc/self/fd/%d", fd); |
280 | 279 | ||
281 | n = readlink(path, buf, sizeof(buf)); | 280 | n = readlink(path, buf, sizeof(buf)); |
282 | if (n < 0) { | 281 | if (n < 0) { |
@@ -304,7 +303,7 @@ char *get_fdinfo(int fd, const char *key) | |||
304 | ssize_t n; | 303 | ssize_t n; |
305 | FILE *fdi; | 304 | FILE *fdi; |
306 | 305 | ||
307 | snprintf(path, sizeof(path), "/proc/%d/fdinfo/%d", getpid(), fd); | 306 | snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd); |
308 | 307 | ||
309 | fdi = fopen(path, "r"); | 308 | fdi = fopen(path, "r"); |
310 | if (!fdi) { | 309 | if (!fdi) { |
diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c index b2ed5ee1af5f..545a92471c33 100644 --- a/tools/bpf/bpftool/jit_disasm.c +++ b/tools/bpf/bpftool/jit_disasm.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <string.h> | 19 | #include <string.h> |
20 | #include <bfd.h> | 20 | #include <bfd.h> |
21 | #include <dis-asm.h> | 21 | #include <dis-asm.h> |
22 | #include <sys/types.h> | ||
23 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
24 | #include <limits.h> | 23 | #include <limits.h> |
25 | 24 | ||
@@ -28,20 +27,12 @@ | |||
28 | 27 | ||
29 | static void get_exec_path(char *tpath, size_t size) | 28 | static void get_exec_path(char *tpath, size_t size) |
30 | { | 29 | { |
30 | const char *path = "/proc/self/exe"; | ||
31 | ssize_t len; | 31 | ssize_t len; |
32 | char *path; | ||
33 | |||
34 | snprintf(tpath, size, "/proc/%d/exe", (int) getpid()); | ||
35 | tpath[size - 1] = 0; | ||
36 | |||
37 | path = strdup(tpath); | ||
38 | assert(path); | ||
39 | 32 | ||
40 | len = readlink(path, tpath, size - 1); | 33 | len = readlink(path, tpath, size - 1); |
41 | assert(len > 0); | 34 | assert(len > 0); |
42 | tpath[len] = 0; | 35 | tpath[len] = 0; |
43 | |||
44 | free(path); | ||
45 | } | 36 | } |
46 | 37 | ||
47 | static int oper_count; | 38 | static int oper_count; |