[PATCH] trace-cmd: Fix extracting instance in RO directory

Steven Rostedt <[email protected]> Fri, 24 Apr 2026 15:15:31 -0400
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
From: Steven Rostedt <[email protected]>

If the extract command is run in a read-only directory like
/sys/kernel/tracing trying to extract an instance buffer, it would fail due
to trying to write one of the temp files in that directory. This is because
extract (and record) still save data for the top level instance (although
the top level instance buffers are not read). It creates temporary files to
do the creation.

Because the top level directory is not used, its instance was not
initialized with an "output file", which is used to know where to create the
temp files for. It then defaults to the local directory, which in this case
is not writable, and the extract fails.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=221389
Reported-by:  Alexander Krabler <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
---
 tracecmd/trace-record.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 1966ec14..e7bb2f58 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -7527,6 +7527,10 @@ void trace_extract(int argc, char **argv)
 		instance->flags |= BUFFER_FL_KEEP;
 	}
 
+	/* Make sure top_instance.output_file exists */
+	if (!top_instance.output_file)
+		top_instance.output_file = strdup(ctx.output);
+
 	/* Extracting data records all events in the system. */
 	if (!ctx.record_all)
 		record_all_events();
-- 
2.51.0