BPF List
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf] libbpf: reset errno after probing kernel features
Date: Mon, 30 Nov 2020 23:40:54 +0100	[thread overview]
Message-ID: <87pn3uwjrd.fsf@toke.dk> (raw)
In-Reply-To: <CAEf4BzZy0Y1hAwOpY=Azod3bSqUKfGNwycGS7s=-DQvTWd8ThA@mail.gmail.com>

Andrii Nakryiko <andrii.nakryiko@gmail.com> writes:

> On Mon, Nov 30, 2020 at 7:42 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>>
>> The kernel feature probing results in 'errno' being set if the probing
>> fails (as is often the case). This can stick around and leak to the caller,
>> which can lead to confusion later. So let's make sure we always reset errno
>> after calling a probe function.
>
> What specifically is the problem and what sort of confusion we are
> talking about here? You are not supposed to check errno, unless the
> function returned -1 or other error result.
>
> In some cases, you have to reset errno manually just to avoid
> confusion (see how strtol() is used, as an example).
>
> I.e., I don't see the problem here, any printf() technically can set
> errno to <0, we don't reset errno after each printf call though,
> right?

Well yeah, technically things work fine in the common case. But this
errno thing sent me on quite the wild goose chase when trying to find
the root cause of the pinning issue I also sent a patch for...

So since reseting errno doesn't hurt either I figured I'd save others
ending up in similar trouble. If it's not to your taste feel free to
just drop the patch :)

-Toke


  reply	other threads:[~2020-11-30 22:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 15:41 [PATCH bpf] libbpf: reset errno after probing kernel features Toke Høiland-Jørgensen
2020-11-30 22:24 ` Andrii Nakryiko
2020-11-30 22:40   ` Toke Høiland-Jørgensen [this message]
2020-12-01  0:18     ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pn3uwjrd.fsf@toke.dk \
    --to=toke@redhat.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox