[PATCH] libtracefs: Have tracefs_{tracing,debug}_dir() make sure it's still mounted

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

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.

Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
---
 src/tracefs-utils.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c
index ae249de06a39..9acf2ad61b16 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);
-- 
2.35.1




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux