From 4051a9e83cb68733af20ce263fcc41c8aadc2622 Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Fri, 17 Dec 2021 14:32:30 -0800 Subject: [PATCH] libbpf-tools: update tcpconnect for libbpf 1.0 Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly. Signed-off-by: Andrii Nakryiko --- libbpf-tools/tcpconnect.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/libbpf-tools/tcpconnect.c b/libbpf-tools/tcpconnect.c index 72448a87a09b..bd3b56b6dcf6 100644 --- a/libbpf-tools/tcpconnect.c +++ b/libbpf-tools/tcpconnect.c @@ -325,17 +325,13 @@ 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; } @@ -343,8 +339,8 @@ static void print_events(int perf_map_fd) 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 */ @@ -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");