libbpf-tools: update opensnoop 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/opensnoop.c

index 935db66195a3f777d618d575c5cf0ead76fc526b..1754b81ebf51c9b43476d534b9e4ee6b19014702 100644 (file)
@@ -220,7 +220,6 @@ int main(int argc, char **argv)
                .parser = parse_arg,
                .doc = argp_program_doc,
        };
-       struct perf_buffer_opts pb_opts;
        struct perf_buffer *pb = NULL;
        struct opensnoop_bpf *obj;
        __u64 time_end = 0;
@@ -230,14 +229,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) {
-               fprintf(stderr, "failed to increase rlimit: %d\n", err);
-               return 1;
-       }
-
        obj = opensnoop_bpf__open();
        if (!obj) {
                fprintf(stderr, "failed to open BPF object\n");
@@ -283,13 +277,10 @@ int main(int argc, char **argv)
        printf("%s\n", "PATH");
 
        /* setup event callbacks */
-       pb_opts.sample_cb = handle_event;
-       pb_opts.lost_cb = handle_lost_events;
        pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES,
-                             &pb_opts);
-       err = libbpf_get_error(pb);
-       if (err) {
-               pb = NULL;
+                             handle_event, handle_lost_events, NULL, NULL);
+       if (!pb) {
+               err = -errno;
                fprintf(stderr, "failed to open perf buffer: %d\n", err);
                goto cleanup;
        }
@@ -307,8 +298,8 @@ int main(int argc, char **argv)
        /* main: poll */
        while (!exiting) {
                err = perf_buffer__poll(pb, PERF_POLL_TIMEOUT_MS);
-               if (err < 0 && errno != EINTR) {
-                       fprintf(stderr, "error polling perf buffer: %s\n", strerror(errno));
+               if (err < 0 && err != -EINTR) {
+                       fprintf(stderr, "error polling perf buffer: %s\n", strerror(-err));
                        goto cleanup;
                }
                if (env.duration && get_ktime_ns() > time_end)