libbpf looks for tracefs files only under debugfs, but tracefs may be mounted even if debugfs is not. When /sys/kernel/debug/tracing is absent, try looking under /sys/kernel/tracing instead. Signed-off-by: Connor O'Brien <connoro@xxxxxxxxxx> --- v1->v2: cache result of debugfs check. src/libbpf.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/libbpf.c b/src/libbpf.c index 2262bcd..cc47c52 100644 --- a/src/libbpf.c +++ b/src/libbpf.c @@ -9945,10 +9945,22 @@ static void gen_kprobe_legacy_event_name(char *buf, size_t buf_sz, __sync_fetch_and_add(&index, 1)); } +static bool debugfs_available(void) +{ + static bool initialized = false, available; + + if (!initialized) { + available = !access("/sys/kernel/debug/tracing", F_OK); + initialized = true; + } + return available; +} + static int add_kprobe_event_legacy(const char *probe_name, bool retprobe, const char *kfunc_name, size_t offset) { - const char *file = "/sys/kernel/debug/tracing/kprobe_events"; + const char *file = debugfs_available() ? "/sys/kernel/debug/tracing/kprobe_events" : + "/sys/kernel/tracing/kprobe_events"; return append_to_file(file, "%c:%s/%s %s+0x%zx", retprobe ? 'r' : 'p', @@ -9958,7 +9970,8 @@ static int add_kprobe_event_legacy(const char *probe_name, bool retprobe, static int remove_kprobe_event_legacy(const char *probe_name, bool retprobe) { - const char *file = "/sys/kernel/debug/tracing/kprobe_events"; + const char *file = debugfs_available() ? "/sys/kernel/debug/tracing/kprobe_events" : + "/sys/kernel/tracing/kprobe_events"; return append_to_file(file, "-:%s/%s", retprobe ? "kretprobes" : "kprobes", probe_name); } @@ -9968,7 +9981,8 @@ static int determine_kprobe_perf_type_legacy(const char *probe_name, bool retpro char file[256]; snprintf(file, sizeof(file), - "/sys/kernel/debug/tracing/events/%s/%s/id", + debugfs_available() ? "/sys/kernel/debug/tracing/events/%s/%s/id" : + "/sys/kernel/tracing/events/%s/%s/id", retprobe ? "kretprobes" : "kprobes", probe_name); return parse_uint_from_file(file, "%d\n"); @@ -10144,7 +10158,8 @@ static void gen_uprobe_legacy_event_name(char *buf, size_t buf_sz, static inline int add_uprobe_event_legacy(const char *probe_name, bool retprobe, const char *binary_path, size_t offset) { - const char *file = "/sys/kernel/debug/tracing/uprobe_events"; + const char *file = debugfs_available() ? "/sys/kernel/debug/tracing/uprobe_events" : + "/sys/kernel/tracing/uprobe_events"; return append_to_file(file, "%c:%s/%s %s:0x%zx", retprobe ? 'r' : 'p', @@ -10154,7 +10169,8 @@ static inline int add_uprobe_event_legacy(const char *probe_name, bool retprobe, static inline int remove_uprobe_event_legacy(const char *probe_name, bool retprobe) { - const char *file = "/sys/kernel/debug/tracing/uprobe_events"; + const char *file = debugfs_available() ? "/sys/kernel/debug/tracing/uprobe_events" : + "/sys/kernel/tracing/uprobe_events"; return append_to_file(file, "-:%s/%s", retprobe ? "uretprobes" : "uprobes", probe_name); } @@ -10164,7 +10180,8 @@ static int determine_uprobe_perf_type_legacy(const char *probe_name, bool retpro char file[512]; snprintf(file, sizeof(file), - "/sys/kernel/debug/tracing/events/%s/%s/id", + debugfs_available() ? "/sys/kernel/debug/tracing/events/%s/%s/id" : + "/sys/kernel/tracing/events/%s/%s/id", retprobe ? "uretprobes" : "uprobes", probe_name); return parse_uint_from_file(file, "%d\n"); @@ -10295,7 +10312,8 @@ static int determine_tracepoint_id(const char *tp_category, int ret; ret = snprintf(file, sizeof(file), - "/sys/kernel/debug/tracing/events/%s/%s/id", + debugfs_available() ? "/sys/kernel/debug/tracing/events/%s/%s/id" : + "/sys/kernel/tracing/events/%s/%s/id", tp_category, tp_name); if (ret < 0) return -errno; -- 2.36.1.124.g0e6072fb45-goog