Re: [PATCH bpf-next v3 2/3] bpftool: fix spurious batch file read error

[email protected]
Newsgroups org.kernel.vger.bpf
Message-ID <7bc009c8016f6c38f063064ae529893180895aadb8da317bfd917a608468d1a8@mail.kernel.org>
> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> index c91e1a6e1a1e..c9a86039c400 100644
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c

[ ... ]

> @@ -429,7 +430,10 @@ static int do_batch(int argc, char **argv)
>  		lines++;
>  	}
>
> -	if (errno && errno != ENOENT) {
> +	if (line_too_long) {
> +		p_err("reading batch file failed: %s", strerror(E2BIG));
> +		err = -1;
> +	} else if (ferror(fp)) {
>  		p_err("reading batch file failed: %s", strerror(errno));
>  		err = -1;
>  	} else {

[ ... ]

This isn't a bug, but now that the batch read check uses ferror() rather
than errno, is the USE_LIBCAP errno = 0 reset in main() still needed?

Looking at main():

#ifdef USE_LIBCAP
	/* Libcap < 2.63 hooks before main() to compute the number of
	 * capabilities of the running kernel, and doing so it calls prctl()
	 * which may fail and set errno to non-zero.
	 * Let's reset errno to make sure this does not interfere with the
	 * batch mode.
	 */
	errno = 0;
#endif

The comment says the reset is specifically to prevent interference with
batch mode, but do_batch() no longer checks errno to detect read failures.
Could this block be dropped alongside the ferror() change?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31367518511
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.