Skip to contentSkip to conversation

libtracefs: Fix tracefs_event_is_enabled() for all events

PATCH New Steven Rostedt 1 participant 1 message Aug 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs: Fix tracefs_event_is_enabled() for all events

From: "Steven Rostedt (Google)" <[email protected]>

When tracefs_event_is_ensabled() is called with both system and event as NULL in order to get the state of all events, it tries to disable all events. This is becaues the call to enable_disable_all() doesn't take the state as a parameter and just looks at the "enable" flag.

Fixes fc94d1a8 ("libtracefs: Add tracefs_event_enable/disable() API")
---
 src/tracefs-events.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
src/tracefs-events.c +14 -3
index 1576153..aabec02 100644
@@ -1511,12 +1511,23 @@ static int enable_disable_system(struct tracefs_instance *instance,
 }
 
 static int enable_disable_all(struct tracefs_instance *instance,
-			      bool enable)
+			      bool enable, enum event_state *state)
 {
 	const char *str = enable ? "1" : "0";
+	char *event_file;
 	int ret;
 
-	ret = tracefs_instance_file_write(instance, "events/enable", str);
+	ret = asprintf(&event_file, "events/enable");
+	if (ret < 0)
+		return ret;
+
+	if (state)
+		ret = read_event_state(instance, event_file, state);
+	else
+
+		ret = tracefs_instance_file_write(instance, event_file, str);
+	free(event_file);
+
 	return ret < 0 ? ret : 0;
 }
 
@@ -1552,7 +1563,7 @@ static int event_enable_disable(struct tracefs_instance *instance,
 
 	/* Handle all events first */
 	if (!system && !event)
-		return enable_disable_all(instance, enable);
+		return enable_disable_all(instance, enable, state);
 
 	systems = tracefs_event_systems(NULL);
 	if (!systems)
Signature · 1 line
2.47.2