All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: preserve errno across pr_warn/pr_info/pr_debug
@ 2022-08-10 18:34 Andrii Nakryiko
  2022-08-10 18:43 ` Daniel Müller
  2022-08-10 18:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2022-08-10 18:34 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team

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>
---
 tools/lib/bpf/libbpf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index f7364ea82ac1..917d975bd4c6 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -223,13 +223,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)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: preserve errno across pr_warn/pr_info/pr_debug
  2022-08-10 18:34 [PATCH bpf-next] libbpf: preserve errno across pr_warn/pr_info/pr_debug Andrii Nakryiko
@ 2022-08-10 18:43 ` Daniel Müller
  2022-08-10 18:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Müller @ 2022-08-10 18:43 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team

On Wed, Aug 10, 2022 at 11:34:25AM -0700, Andrii Nakryiko wrote:
> 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>
> ---
>  tools/lib/bpf/libbpf.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index f7364ea82ac1..917d975bd4c6 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -223,13 +223,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)
> -- 
> 2.30.2
> 

The change looks good to me.

Acked-by: Daniel Müller <deso@posteo.net>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: preserve errno across pr_warn/pr_info/pr_debug
  2022-08-10 18:34 [PATCH bpf-next] libbpf: preserve errno across pr_warn/pr_info/pr_debug Andrii Nakryiko
  2022-08-10 18:43 ` Daniel Müller
@ 2022-08-10 18:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-10 18:50 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Wed, 10 Aug 2022 11:34:25 -0700 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [bpf-next] libbpf: preserve errno across pr_warn/pr_info/pr_debug
    https://git.kernel.org/bpf/bpf-next/c/d7c5802faff6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-10 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10 18:34 [PATCH bpf-next] libbpf: preserve errno across pr_warn/pr_info/pr_debug Andrii Nakryiko
2022-08-10 18:43 ` Daniel Müller
2022-08-10 18:50 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.