From 009b9fc0771523636f8190fa8ba4ebc6ee21b23c Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Mon, 21 Nov 2022 10:48:25 -0800 Subject: [PATCH] libbpf-tools: fix biosnoop exit code perf_buffer__poll returns a count or a negative error value. If the loop is broken because of timeout err needs to be zero or else an error is flagged. As the count may be non-zero, and this isn't an error, move the setting of err to zero earlier. This also allows switching a goto to a break. --- libbpf-tools/biosnoop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libbpf-tools/biosnoop.c b/libbpf-tools/biosnoop.c index 988d82566ecf..8e228d3d1b63 100644 --- a/libbpf-tools/biosnoop.c +++ b/libbpf-tools/biosnoop.c @@ -334,10 +334,10 @@ int main(int argc, char **argv) fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err)); goto cleanup; } - if (env.duration && get_ktime_ns() > time_end) - goto cleanup; /* reset err to return 0 if exiting */ err = 0; + if (env.duration && get_ktime_ns() > time_end) + break; } cleanup: