mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-28 04:09:06 +08:00
libbpf: Ensure libbpf always opens files with O_CLOEXEC
Make sure that libbpf code always gets FD with O_CLOEXEC flag set, regardless if file is open through open() or fopen(). For the latter this means to add "e" to mode string, which is supported since pretty ancient glibc v2.7. Also drop the outdated TODO comment in usdt.c, which was already completed. Suggested-by: Lennart Poettering <lennart@poettering.net> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20230525221311.2136408-1-andrii@kernel.org
This commit is contained in:
committed by
Andrii Nakryiko
parent
cb23f981c3
commit
ba7a44da68
@@ -4351,7 +4351,7 @@ static int bpf_get_map_info_from_fdinfo(int fd, struct bpf_map_info *info)
|
||||
snprintf(file, sizeof(file), "/proc/%d/fdinfo/%d", getpid(), fd);
|
||||
memset(info, 0, sizeof(*info));
|
||||
|
||||
fp = fopen(file, "r");
|
||||
fp = fopen(file, "re");
|
||||
if (!fp) {
|
||||
err = -errno;
|
||||
pr_warn("failed to open %s: %d. No procfs support?\n", file,
|
||||
@@ -7455,7 +7455,7 @@ int libbpf_kallsyms_parse(kallsyms_cb_t cb, void *ctx)
|
||||
int ret, err = 0;
|
||||
FILE *f;
|
||||
|
||||
f = fopen("/proc/kallsyms", "r");
|
||||
f = fopen("/proc/kallsyms", "re");
|
||||
if (!f) {
|
||||
err = -errno;
|
||||
pr_warn("failed to open /proc/kallsyms: %d\n", err);
|
||||
@@ -10075,7 +10075,7 @@ static int parse_uint_from_file(const char *file, const char *fmt)
|
||||
int err, ret;
|
||||
FILE *f;
|
||||
|
||||
f = fopen(file, "r");
|
||||
f = fopen(file, "re");
|
||||
if (!f) {
|
||||
err = -errno;
|
||||
pr_debug("failed to open '%s': %s\n", file,
|
||||
|
||||
Reference in New Issue
Block a user