linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libtracefs: Have tracefs_{tracing,debug}_dir() make sure it's still mounted
@ 2022-12-11  0:11 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2022-12-11  0:11 UTC (permalink / raw)
  To: Linux Trace Devel

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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@goodmis.org>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-11  0:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-11  0:11 [PATCH] libtracefs: Have tracefs_{tracing,debug}_dir() make sure it's still mounted Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).