Re: [PATCH bpf-next v3] bpftool: use only nftw for file tree parsing
From: Tony Ambardar <hidden>
Date: 2020-07-21 02:15:01
Also in:
bpf
On Mon, 20 Jul 2020 at 01:13, Quentin Monnet [off-list ref] wrote:
On 17/07/2020 23:55, Tony Ambardar wrote:quoted
The bpftool sources include code to walk file trees, but use multiple frameworks to do so: nftw and fts. While nftw conforms to POSIX/SUSv3 and is widely available, fts is not conformant and less common, especially on non-glibc systems. The inconsistent framework usage hampers maintenance and portability of bpftool, in particular for embedded systems. Standardize code usage by rewriting one fts-based function to use nftw and clean up some related function warnings by extending use of "const char *" arguments. This change helps in building bpftool against musl for OpenWrt.
[...]
quoted
int build_pinned_obj_table(struct pinned_obj_table *tab, enum bpf_obj_type type) {[...]quoted
while ((mntent = getmntent(mntfile))) {[...]quoted
- while ((ftse = fts_read(fts))) {[...]quoted
+ if (nftw(path, do_build_table_cb, nopenfd, flags) == -1) + break;Sorry I missed that on the previous reviews; but I think a simple break out of the loop changes the previous behaviour, we should instead "return -1" from build_pinned_obj_table() if nftw() returns -1, as we were doing so far.
Thanks for the catch. Sorry, that's totally my fault: this was meant to be an "err = nftw(...)" with a "return err" on the common exit path, similar to the rest of the patch. Let me fix and resend. Kind regards, Tony
Looks good otherwise.quoted
} fclose(mntfile); return 0;