diff options
author | Andrii Nakryiko <andriin@fb.com> | 2019-05-29 20:36:04 +0300 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-05-30 02:23:34 +0300 |
commit | be5c5d4e9d8cbdd7fcdcbc45e86e34bc0bd1cefd (patch) | |
tree | 792ac7428a29e496e2ce8f5622e81570fa89872d /tools/lib/bpf/libbpf.c | |
parent | 8ca990ce0d402d5aaf05f7a33ff025fcbcbb5f93 (diff) | |
download | linux-be5c5d4e9d8cbdd7fcdcbc45e86e34bc0bd1cefd.tar.xz |
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>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index c985a7916e35..40690b7e500e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -565,12 +565,12 @@ static int bpf_object__elf_init(struct bpf_object *obj) } else { obj->efile.fd = open(obj->path, O_RDONLY); if (obj->efile.fd < 0) { - char errmsg[STRERR_BUFSIZE]; - char *cp = libbpf_strerror_r(errno, errmsg, - sizeof(errmsg)); + char errmsg[STRERR_BUFSIZE], *cp; + err = -errno; + cp = libbpf_strerror_r(err, errmsg, sizeof(errmsg)); pr_warning("failed to open %s: %s\n", obj->path, cp); - return -errno; + return err; } obj->efile.elf = elf_begin(obj->efile.fd, |