53 lines
1.6 KiB
Diff
53 lines
1.6 KiB
Diff
From 45dca19bd2f3fff624f03e903be9241af7cb26c6 Mon Sep 17 00:00:00 2001
|
|
From: Andrii Nakryiko <andrii@kernel.org>
|
|
Date: Wed, 10 Aug 2022 11:34:25 -0700
|
|
Subject: [PATCH] libbpf: preserve errno across pr_warn/pr_info/pr_debug
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
As suggested in [0], make sure that libbpf_print saves and restored
|
|
errno and as such guaranteed that no matter what actual print callback
|
|
user installs, macros like pr_warn/pr_info/pr_debug are completely
|
|
transparent as far as errno goes.
|
|
|
|
While libbpf code is pretty careful about not clobbering important errno
|
|
values accidentally with pr_warn(), it's a trivial change to make sure
|
|
that pr_warn can be used anywhere without a risk of clobbering errno.
|
|
|
|
No functional changes, just future proofing.
|
|
|
|
[0] https://github.com/libbpf/libbpf/pull/536
|
|
|
|
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
|
|
Acked-by: Daniel Müller <deso@posteo.net>
|
|
Link: https://lore.kernel.org/r/20220810183425.1998735-1-andrii@kernel.org
|
|
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
|
|
---
|
|
src/libbpf.c | 5 +++++
|
|
1 file changed, 5 insertions(+)
|
|
|
|
diff --git a/src/libbpf.c b/src/libbpf.c
|
|
index f7364ea8..917d975b 100644
|
|
--- a/src/libbpf.c
|
|
+++ b/src/libbpf.c
|
|
@@ -95,13 +95,18 @@ __printf(2, 3)
|
|
void libbpf_print(enum libbpf_print_level level, const char *format, ...)
|
|
{
|
|
va_list args;
|
|
+ int old_errno;
|
|
|
|
if (!__libbpf_pr)
|
|
return;
|
|
|
|
+ old_errno = errno;
|
|
+
|
|
va_start(args, format);
|
|
__libbpf_pr(level, format, args);
|
|
va_end(args);
|
|
+
|
|
+ errno = old_errno;
|
|
}
|
|
|
|
static void pr_perm_msg(int err)
|