diff mbox series

libtracefs: Fix tracefs_instance_reset to clear synthetic events

Message ID 20240105235720.6f0bb664@rorschach.local.home (mailing list archive)
State Accepted
Commit 93e20af8282369bd3bf7d99a2d302332ccb8d2ba
Headers show
Series libtracefs: Fix tracefs_instance_reset to clear synthetic events | expand

Commit Message

Steven Rostedt Jan. 6, 2024, 4:57 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

tracefs_instance_reset() was not clearing synthetic events as there's an
order that is needed in clearing out the triggers.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/tracefs-instance.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index b94630a324a1..0ee0225e0222 100644
--- a/src/tracefs-instance.c
+++ b/src/tracefs-instance.c
@@ -1481,9 +1481,12 @@  void tracefs_instance_reset(struct tracefs_instance *instance)
 	int has_trigger = -1;
 	char **systems;
 	struct stat st;
+	char **file_list = NULL;
+	int list_size = 0;
 	char **events;
 	char *file;
 	int i, j;
+	int ret;
 
 	tracefs_trace_off(instance);
 	disable_func_stack_trace_instance(instance);
@@ -1514,8 +1517,15 @@  void tracefs_instance_reset(struct tracefs_instance *instance)
 					else
 						has_trigger = 1;
 				}
-				if (has_trigger)
-					clear_trigger(file);
+				if (has_trigger) {
+					ret = clear_trigger(file);
+					if (ret) {
+						char **list;
+						list = tracefs_list_add(file_list, file);
+						if (list)
+							file_list = list;
+					}
+				}
 				tracefs_put_tracing_file(file);
 			}
 			tracefs_list_free(events);
@@ -1523,6 +1533,25 @@  void tracefs_instance_reset(struct tracefs_instance *instance)
 		tracefs_list_free(systems);
 	}
 
+	while (file_list && list_size != tracefs_list_size(file_list)) {
+		char **list = file_list;
+
+		list_size = tracefs_list_size(file_list);
+		file_list = NULL;
+		for (i = 0; list[i]; i++) {
+			ret = clear_trigger(file);
+			if (ret) {
+				char **tlist;
+				tlist = tracefs_list_add(file_list, list[i]);
+				if (tlist)
+					file_list = tlist;
+			}
+		}
+		tracefs_list_free(list);
+	}
+	tracefs_list_free(file_list);
+
+	tracefs_instance_file_write(instance, "synthetic_events", " ");
 	tracefs_instance_file_write(instance, "error_log", " ");
 	tracefs_instance_file_write(instance, "trace_clock", "local");
 	tracefs_instance_file_write(instance, "set_event_pid", "");