From: Geliang Tang <[email protected]>

Errno 95 (ENOTSUP or EOPNOTSUPP) can be recognized by libbpf_strerror_r(),
but 524 (ENOTSUPP) can't:

 prog 'basic_alloc3': BPF program load failed: Operation not supported
 prog 'basic_alloc3': failed to load: -95
 failed to load object 'verifier_arena'
 FAIL:unexpected_load_failure unexpected error: -95 (errno 95)

 prog 'inner_map': BPF program load failed: unknown error (-524)
 prog 'inner_map': failed to load: -524
 failed to load object 'bloom_filter_map'
 failed to load BPF skeleton 'bloom_filter_map': -524
 FAIL:bloom_filter_map__open_and_load unexpected error: -524

This patch fixes this by handling ENOTSUPP in libbpf_strerror_r(). With
this change, the new error string looks like:

 prog 'inner_map': BPF program load failed: Operation not supported

Signed-off-by: Geliang Tang <[email protected]>
---
 tools/lib/bpf/str_error.c | 18 +++++++++++++-----
 tools/lib/bpf/str_error.h |  4 ++++
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c
index 5e6a1e27ddf9..5eef2bc7fac5 100644
--- a/tools/lib/bpf/str_error.c
+++ b/tools/lib/bpf/str_error.c
@@ -15,7 +15,8 @@
  */
 char *libbpf_strerror_r(int err, char *dst, int len)
 {
-       int ret = strerror_r(err < 0 ? -err : err, dst, len);
+       unsigned int no = err < 0 ? -err : err;
+       int ret = strerror_r(no, dst, len);
        /* on glibc <2.13, ret == -1 and errno is set, if strerror_r() can't
         * handle the error, on glibc >=2.13 *positive* (errno-like) error
         * code is returned directly
@@ -23,11 +24,18 @@ char *libbpf_strerror_r(int err, char *dst, int len)
        if (ret == -1)
                ret = errno;
        if (ret) {
-               if (ret == EINVAL)
-                       /* strerror_r() doesn't recognize this specific error */
-                       snprintf(dst, len, "unknown error (%d)", err < 0 ? err 
: -err);
-               else
+               if (ret == EINVAL) {
+                       switch (no) {
+                       case ENOTSUPP:
+                               snprintf(dst, len, "Operation not supported");
+                               break;
+                       default:
+                               /* strerror_r() doesn't recognize this specific 
error */
+                               snprintf(dst, len, "unknown error (-%u)", no);
+                       }
+               } else {
                        snprintf(dst, len, "ERROR: strerror_r(%d)=%d", err, 
ret);
+               }
        }
        return dst;
 }
diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h
index 626d7ffb03d6..c41f6ba133cf 100644
--- a/tools/lib/bpf/str_error.h
+++ b/tools/lib/bpf/str_error.h
@@ -4,6 +4,10 @@
 
 #define STRERR_BUFSIZE  128
 
+#ifndef ENOTSUPP
+#define ENOTSUPP 524
+#endif
+
 char *libbpf_strerror_r(int err, char *dst, int len);
 
 #endif /* __LIBBPF_STR_ERROR_H */
-- 
2.43.0


Reply via email to