From fd4f5d189c1d77f80bfff60a05958aead7aa07aa Mon Sep 17 00:00:00 2001 From: li-long315 Date: Mon, 26 Jun 2023 17:19:39 +0800 Subject: [PATCH] Set permissions and print functions for the libbpf library --- observation/src/vfsstat/vfsstat.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/observation/src/vfsstat/vfsstat.c b/observation/src/vfsstat/vfsstat.c index ed1c988f..87d31053 100644 --- a/observation/src/vfsstat/vfsstat.c +++ b/observation/src/vfsstat/vfsstat.c @@ -52,6 +52,14 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) return 0; } +static int libbpf_print_fn(enum libbpf_print_level level, const char *format, + va_list args) +{ + if (level == LIBBPF_DEBUG && !env.verbose) + return 0; + return vfprintf(stderr, format, args); +} + int main(int argc, char *argv[]) { LIBBPF_OPTS(bpf_object_open_opts, open_opts); @@ -66,6 +74,11 @@ int main(int argc, char *argv[]) err = argp_parse(&argp, argc, argv, 0, NULL, NULL); if (err) return err; + + if (!bpf_is_root()) + return 1; + + libbpf_set_print(libbpf_print_fn); return err != 0; } -- Gitee