libbpf-tools: update tcpconnect for libbpf 1.0
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 17 Dec 2021 22:32:30 +0000 (14:32 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 20 Dec 2021 21:21:26 +0000 (13:21 -0800)
Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
libbpf-tools/tcpconnect.c

index 72448a87a09bb092559bd4379ea7fe8e6449941a..bd3b56b6dcf66ac1fe59c954f874d5743555552f 100644 (file)
@@ -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");