trace-cmd: Fix extracting instance in RO directory 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://lore.kernel.org/20260424151531.3c9be298@gandalf.local.home Link: https://bugzilla.kernel.org/show_bug.cgi?id=221389 Reported-by: Alexander Krabler <code@a.krabler.eu> Tested-by: Alexander Krabler <code@a.krabler.eu> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 9fbd60a..966901f 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c
@@ -7512,6 +7512,10 @@ 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();