Skip to content

Commit

Permalink
utils: Add logic to search when the default path for tracefs is not p…
Browse files Browse the repository at this point in the history
…resent

Find the tracefs path in /proc/mounts with the mntent functions

Signed-off-by: gichoelchoi <gichoel3101@gmail.com>
  • Loading branch information
gichoel committed Jul 30, 2023
1 parent ca35cc2 commit bc8c281
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions utils/tracefs.c
Expand Up @@ -9,25 +9,43 @@
#include "utils/utils.h"

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

static char *TRACING_DIR = NULL;

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

if (TRACING_DIR)
return true;

if (!statfs(TRACEFS_DIR_PATH, &fs) && fs.f_type == TRACEFS_MAGIC) {
xasprintf(&TRACING_DIR, "%s", TRACEFS_DIR_PATH);
pr_dbg2("TRACING_DIR : %s\n", TRACING_DIR);

return true;
}

pr_dbg2("tracefs or debugfs not found..! \n");
fp = setmntent(PROC_MOUNTS_DIR_PATH, "r");
if (fp == NULL)
return false;

while ((ent = getmntent(fp)) != NULL) {
if (strcmp(ent->mnt_fsname, "tracefs"))
continue;

xasprintf(&TRACING_DIR, "%s", ent->mnt_dir);
found = true;
break;
}

endmntent(fp);

if (found != true)
pr_dbg2("tracefs or debugfs not found..! \n");

return found;
}
Expand Down

0 comments on commit bc8c281

Please sign in to comment.