Skip to content

bpf: convert ENOENT to Unsupported

Unfortunately libbpf gives us ENOENT when it fails to load BPFs that require struct_ops support. libbpf (not libbpf_rs) prints a warning:

  WARN - libbpf: struct_ops init_kern: struct bpf_struct_ops_hid_bpf_ops
  is not found in kernel BTF

but that warning is not trivial to intercept since it happens mostly out-of-band through the print_to_log() handler.

So we do our best: we check if we have NotFound and assume that our previous checks for looking up actual files worked fine so any NotFound here means "unsupported" instead.

This vastly improves the error message from

   WARN - Failed to load "build/src/bpf/10-Huion__Inspiroy-2-S.bpf.o":
   No such file or directory (os error 2)

to this:

   WARN - Failed to load "build/src/bpf/10-Huion__Inspiroy-2-S.bpf.o":
   unsupported on this kernel

Merge request reports

Loading