summaryrefslogtreecommitdiff
path: root/tools/lib/bpf/libbpf_internal.h
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2022-12-29 19:12:17 -0800
committerAlexei Starovoitov <ast@kernel.org>2022-12-29 19:18:08 -0800
commitbb5747cfbc4b7fe29621ca6cd4a695d2723bf2e8 (patch)
treed5bc0780aa6ae6d11b1f172031fcd0753f0a13ba /tools/lib/bpf/libbpf_internal.h
parent678a1c036199011e65b203367900f002a28da004 (diff)
libbpf: Restore errno after pr_warn.
pr_warn calls into user-provided callback, which can clobber errno, so `errno = saved_errno` should happen after pr_warn. Fixes: 07453245620c ("libbpf: fix errno is overwritten after being closed.") Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/libbpf_internal.h')
-rw-r--r--tools/lib/bpf/libbpf_internal.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 98333a6c38e9..e4d05662a96c 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -544,8 +544,10 @@ static inline int ensure_good_fd(int fd)
saved_errno = errno;
close(old_fd);
errno = saved_errno;
- if (fd < 0)
+ if (fd < 0) {
pr_warn("failed to dup FD %d to FD > 2: %d\n", old_fd, -saved_errno);
+ errno = saved_errno;
+ }
}
return fd;
}