mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 08:09:07 +08:00
libbpf: preserve errno before calling into user callback
pr_warning ultimately may call into user-provided callback function, which can clobber errno value, so we need to save it before that. Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
committed by
Andrii Nakryiko
parent
1aedc35d5d
commit
64852b2fb9
@@ -565,12 +565,12 @@ static int bpf_object__elf_init(struct bpf_object *obj)
|
|||||||
} else {
|
} else {
|
||||||
obj->efile.fd = open(obj->path, O_RDONLY);
|
obj->efile.fd = open(obj->path, O_RDONLY);
|
||||||
if (obj->efile.fd < 0) {
|
if (obj->efile.fd < 0) {
|
||||||
char errmsg[STRERR_BUFSIZE];
|
char errmsg[STRERR_BUFSIZE], *cp;
|
||||||
char *cp = libbpf_strerror_r(errno, errmsg,
|
|
||||||
sizeof(errmsg));
|
|
||||||
|
|
||||||
|
err = -errno;
|
||||||
|
cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg));
|
||||||
pr_warning("failed to open %s: %s\n", obj->path, cp);
|
pr_warning("failed to open %s: %s\n", obj->path, cp);
|
||||||
return -errno;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj->efile.elf = elf_begin(obj->efile.fd,
|
obj->efile.elf = elf_begin(obj->efile.fd,
|
||||||
|
|||||||
Reference in New Issue
Block a user