diff options
author | Tianyi Liu <i.pear@outlook.com> | 2022-09-28 16:09:32 +0800 |
---|---|---|
committer | Quentin Monnet <qmonnet+github@qoba.lt> | 2022-10-20 10:34:34 +0100 |
commit | acba8406e10f7c70ce410790d1958974631a4e19 (patch) | |
tree | c76f339f029dc1026f60de3fb263e8bd25a36202 /src/map_perf_ring.c | |
parent | e069a5c22a8b2a94243af7a0ae7052f6dc2a29aa (diff) | |
download | bpftool-acba8406e10f7c70ce410790d1958974631a4e19.tar.gz |
bpftool: Fix error message of strerror
strerror() expects a positive errno, however variable err will never be
positive when an error occurs. This causes bpftool to output too many
"unknown error", even a simple "file not exist" error can not get an
accurate message.
This patch fixed all "strerror(err)" patterns in bpftool.
Specially in btf.c#L823, hashmap__append() is an internal function of
libbpf and will not change errno, so there's a little difference.
Some libbpf_get_error() calls are kept for return values.
Changes since v1: https://lore.kernel.org/bpf/SY4P282MB1084B61CD8671DFA395AA8579D539@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM/
Check directly for NULL values instead of calling libbpf_get_error().
Signed-off-by: Tianyi Liu <i.pear@outlook.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/SY4P282MB1084AD9CD84A920F08DF83E29D549@SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM
Diffstat (limited to 'src/map_perf_ring.c')
-rw-r--r-- | src/map_perf_ring.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/map_perf_ring.c b/src/map_perf_ring.c index 1583281..21d7d44 100644 --- a/src/map_perf_ring.c +++ b/src/map_perf_ring.c @@ -188,10 +188,9 @@ int do_event_pipe(int argc, char **argv) opts.map_keys = &ctx.idx; pb = perf_buffer__new_raw(map_fd, MMAP_PAGE_CNT, &perf_attr, print_bpf_output, &ctx, &opts); - err = libbpf_get_error(pb); - if (err) { + if (!pb) { p_err("failed to create perf buffer: %s (%d)", - strerror(err), err); + strerror(errno), errno); goto err_close_map; } @@ -206,7 +205,7 @@ int do_event_pipe(int argc, char **argv) err = perf_buffer__poll(pb, 200); if (err < 0 && err != -EINTR) { p_err("perf buffer polling failed: %s (%d)", - strerror(err), err); + strerror(errno), errno); goto err_close_pb; } } |