Skip to content

Commit

Permalink
libbpf-tools: fix biosnoop exit code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
captain5050 authored and chenhengqi committed Nov 22, 2022
1 parent 099965f commit 009b9fc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libbpf-tools/biosnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 009b9fc

Please sign in to comment.