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

Steven Rostedt <[email protected]>
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
From: "Steven Rostedt (VMware)" <[email protected]>

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

Signed-off-by: Steven Rostedt (VMware) <[email protected]>
---
 tracecmd/trace-list.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

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);
 }
 
 
-- 
2.45.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.