Skip to content

Commit

Permalink
utils: Add logic to check for hardcoded tracefs paths first
Browse files Browse the repository at this point in the history
The logic we added previously was to use '/proc/mounts'
to find the tracefs path.

However, the logic can be simplified even further by
using the canonical ftrace path, as per commit from
torvalds/linux@2455f0e.

Link: https://git.kernel.org/torvalds/c/2455f0e124d3
Signed-off-by: Gichoel Choi <gichoel3101@gmail.com>
  • Loading branch information
gichoel committed Aug 9, 2023
1 parent 13cea8b commit c9b7691
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions utils/tracefs.c
@@ -1,23 +1,34 @@
#include <fcntl.h>
#include <linux/magic.h>
#include <mntent.h>
#include <stdio.h>
#include <string.h>
#include <sys/vfs.h>

#include "utils/tracefs.h"
#include "utils/utils.h"

#define PROC_MOUNTS_DIR_PATH "/proc/mounts"
#define TRACEFS_DIR_PATH "/sys/kernel/tracing"
#define OLD_TRACEFS_DIR_PATH "/sys/kernel/debug/tracing"

static char *TRACING_DIR = NULL;

static bool find_tracing_dir(void)
{
FILE *fp;
struct mntent *ent;
struct statfs fs;

if (TRACING_DIR)
return true;

if ((!statfs(TRACEFS_DIR_PATH, &fs) && fs.f_type == TRACEFS_MAGIC) ||
(!statfs(OLD_TRACEFS_DIR_PATH, &fs) && fs.f_type == TRACEFS_MAGIC)) {
xasprintf(&TRACING_DIR, "%s", TRACEFS_DIR_PATH);
return true;
}

fp = setmntent(PROC_MOUNTS_DIR_PATH, "r");
if (fp == NULL)
return false;
Expand Down

0 comments on commit c9b7691

Please sign in to comment.