Skip to content

Commit

Permalink
libbpf-tools: update tcpconnect for libbpf 1.0
Browse files Browse the repository at this point in the history
Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly.

Signed-off-by: Andrii Nakryiko <[email protected]>
  • Loading branch information
anakryiko committed Dec 20, 2021
1 parent d2dc7bc commit 4051a9e
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions libbpf-tools/tcpconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,26 +325,22 @@ static void handle_lost_events(void *ctx, int cpu, __u64 lost_cnt)

static void print_events(int perf_map_fd)
{
struct perf_buffer_opts pb_opts = {
.sample_cb = handle_event,
.lost_cb = handle_lost_events,
};
struct perf_buffer *pb = NULL;
struct perf_buffer *pb;
int err;

pb = perf_buffer__new(perf_map_fd, 128, &pb_opts);
err = libbpf_get_error(pb);
if (err) {
pb = NULL;
pb = perf_buffer__new(perf_map_fd, 128,
handle_event, handle_lost_events, NULL, NULL);
if (!pb) {
err = -errno;
warn("failed to open perf buffer: %d\n", err);
goto cleanup;
}

print_events_header();
while (!exiting) {
err = perf_buffer__poll(pb, 100);
if (err < 0 && errno != EINTR) {
warn("error polling perf buffer: %s\n", strerror(errno));
if (err < 0 && err != -EINTR) {
warn("error polling perf buffer: %s\n", strerror(-err));
goto cleanup;
}
/* reset err to return 0 if exiting */
Expand All @@ -370,14 +366,9 @@ int main(int argc, char **argv)
if (err)
return err;

libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
libbpf_set_print(libbpf_print_fn);

err = bump_memlock_rlimit();
if (err) {
warn("failed to increase rlimit: %s\n", strerror(errno));
return 1;
}

obj = tcpconnect_bpf__open();
if (!obj) {
warn("failed to open BPF object\n");
Expand Down

0 comments on commit 4051a9e

Please sign in to comment.