diff mbox series

[3/4] trace-cmd list: Use tracefs_instances() to list instances

Message ID 20241011182752.357499-4-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit e45400794a7b1b344aff0065dd3a4e2b2c16cd6a
Headers show
Series trace-cmd: Various updates | expand

Commit Message

Steven Rostedt Oct. 11, 2024, 6:26 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Instead of walking the instances directory, use the tracefs_instances()
function to find all the instances.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-list.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 0fbb8eabd44b..8badd1f2e3e3 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -484,31 +484,20 @@  static void show_functions(const char *funcre)
 
 static void show_buffers(void)
 {
-	struct dirent *dent;
-	DIR *dir;
-	char *path;
-	int printed = 0;
+	char **list;
+	int i;
 
-	path = tracefs_get_tracing_file("instances");
-	dir = opendir(path);
-	tracefs_put_tracing_file(path);
-	if (!dir)
+	list = tracefs_instances(NULL);
+	if (!list)
 		die("Can not read instance directory");
 
-	while ((dent = readdir(dir))) {
-		const char *name = dent->d_name;
-
-		if (strcmp(name, ".") == 0 ||
-		    strcmp(name, "..") == 0)
-			continue;
-
-		printf("%s\n", name);
-		printed = 1;
-	}
-	closedir(dir);
+	for (i = 0; list[i]; i++)
+		printf("%s\n", list[i]);
 
-	if (!printed)
+	if (!i)
 		printf("No buffer instances defined\n");
+
+	tracefs_list_free(list);
 }