From dfc688b5e594c8e7f6c15f02ad5b1382096e33a6 Mon Sep 17 00:00:00 2001 From: springzfx Date: Sat, 30 May 2020 01:43:37 +0800 Subject: [PATCH] linux-headers needed fot bpf init --- src/execsnoop.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/execsnoop.cpp b/src/execsnoop.cpp index f32ecc8..c83ad31 100644 --- a/src/execsnoop.cpp +++ b/src/execsnoop.cpp @@ -59,9 +59,15 @@ void handle_events(void *cb_cookie, void *data, int data_size) { int execsnoop() { debug("starting execsnoop"); ebpf::BPF bpf; - auto init_res = bpf.init(BPF_PROGRAM); - if (init_res.code() != 0) { - std::cerr << init_res.msg() << std::endl; + + try { + auto init_res = bpf.init(BPF_PROGRAM); + if (init_res.code() != 0) { + std::cerr << init_res.msg() << std::endl; + return 1; + } + } catch (exception &e) { + error("bpf init failed, maybe linux-headers not installed: %s", e.what()); return 1; }