Skip to content

Commit

Permalink
retsnoop: fallback to debugfs mount point if tracefs is not mounted
Browse files Browse the repository at this point in the history
Let retsnoop to fallback to debugfs mount point
(/sys/kernel/debug/tracing) if tracefs (/sys/kernel/tracing) isn't
mounted.

Signed-off-by: Feng Zhou <[email protected]>
  • Loading branch information
zf1575192187 authored and anakryiko committed Feb 3, 2023
1 parent 9fc3ca6 commit 4260e81
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/mass_attacher.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sys/syscall.h>
#include <linux/perf_event.h>
#include <unistd.h>
#include <fcntl.h>
#include "mass_attacher.h"
#include "ksyms.h"
#include "calib_feat.skel.h"
Expand Down Expand Up @@ -701,10 +702,28 @@ static int kprobe_by_name(const void *a, const void *b)
#define str_has_pfx(str, pfx) \
(strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)

#define DEBUGFS "/sys/kernel/debug/tracing"
#define TRACEFS "/sys/kernel/tracing"

static bool use_debugfs(void)
{
static int has_debugfs = -1;

if (has_debugfs < 0)
has_debugfs = faccessat(AT_FDCWD, DEBUGFS, F_OK, AT_EACCESS) == 0;

return has_debugfs == 1;
}

static const char *tracefs_available_filter_functions(void)
{
return use_debugfs() ? DEBUGFS"/available_filter_functions" : TRACEFS"/available_filter_functions";
}

static int load_available_kprobes(struct mass_attacher *att)
{
static char buf[512];
const char *fname = "/sys/kernel/tracing/available_filter_functions";
const char *fname = tracefs_available_filter_functions();
int cnt, err;
void *tmp, *s;
FILE *f;
Expand Down

0 comments on commit 4260e81

Please sign in to comment.