aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-12-10 19:11:12 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-12-10 20:06:13 -0500
commit92c9292ae9c521e63e826d6ade3ceff7e7151020 (patch)
treec9d3969e4d8b6a6ec1f79d066f6b785c013d2975
parent378a9ddddafc583c50a8ef2d33d06abf7df3109e (diff)
downloadlibtracefs-92c9292ae9c521e63e826d6ade3ceff7e7151020.tar.gz
libtracefs: Have tracefs_{tracing,debug}_dir() make sure it's still mounted
The test to test tracefs_tracing_dir() actually did not mount the tracing_dir but only returned where it was mounted. This was because the setup of the tests already called tracefs_tracing_dir() and set the static variable to it. As the tracefs_tracing_dir() function already found the mounted tracefs file system, it cached the location. The test unmounted it, and then called tracefs_tracing_dir(), and since that returned a path, the test assumed (incorrectly) that it was mounted. Have tracefs_tracing_dir() and tracefs_debug_dir() check to make sure each time that the cached directory is still mounted by checking for a file/directory in it. For tracefs, it checks to see if "trace" exists. For debugfs, it checks to see if "tracing" exists. Link: https://lore.kernel.org/linux-trace-devel/20221210191112.749f045c@gandalf.local.home Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--src/tracefs-utils.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c
index ae249de..9acf2ad 100644
--- a/src/tracefs-utils.c
+++ b/src/tracefs-utils.c
@@ -230,6 +230,16 @@ int tracefs_set_tracing_dir(char *tracing_dir)
return 0;
}
+/* Used to check if the directory is still mounted */
+static int test_dir(const char *dir, const char *file)
+{
+ char path[strlen(dir) + strlen(file) + 2];
+ struct stat st;
+
+ sprintf(path, "%s/%s", dir, file);
+ return stat(path, &st) < 0 ? 0 : 1;
+}
+
/**
* tracefs_tracing_dir - Get tracing directory
*
@@ -240,10 +250,11 @@ const char *tracefs_tracing_dir(void)
{
static const char *tracing_dir;
+ /* Do not check custom_tracing_dir */
if (custom_tracing_dir)
return custom_tracing_dir;
- if (tracing_dir)
+ if (tracing_dir && test_dir(tracing_dir, "trace"))
return tracing_dir;
tracing_dir = find_tracing_dir(false, true);
@@ -261,7 +272,7 @@ const char *tracefs_debug_dir(void)
{
static const char *debug_dir;
- if (debug_dir)
+ if (debug_dir && test_dir(debug_dir, "tracing"))
return debug_dir;
debug_dir = find_tracing_dir(true, true);