All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] trace-cmd record: Fix top_instance.output_file being NULL
Date: Fri, 19 Jan 2024 16:27:43 -0500	[thread overview]
Message-ID: <20240119162743.1a107fa9@gandalf.local.home> (raw)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If the -o comes after a -B, the output_file name will be associated to the
trace instance of that -B, and the top_instance.output_file will be NULL.
If recording is started in a location that is read-only, the temp file
created for the top instance is going to try to be created in that read-only
file system.

 /sys/kernel/tracing# trace-cmd record -o /tmp/test.dat -B test -e sched
 Hit Ctrl^C to stop recording
 ^Ctrace-cmd: Permission denied
   could not create file (null).cpu0

Make sure all instances, including the top_instance has their output_file
correct.

Also, because the output file could have been created under another
instance, check if that instance already has the output file before
assigning over it.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-record.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 762afba4..91cc90d4 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -7122,6 +7122,10 @@ static void record_trace(int argc, char **argv,
 	if (!ctx->output)
 		ctx->output = DEFAULT_INPUT_FILE;
 
+	/* Make sure top_instance.output_file exists */
+	if (!top_instance.output_file)
+		top_instance.output_file = strdup(ctx->output);
+
 	if (ctx->data_flags & (DATA_FL_GUEST | DATA_FL_PROXY))
 		set_tsync_params(ctx);
 
@@ -7131,7 +7135,9 @@ static void record_trace(int argc, char **argv,
 	for_all_instances(instance) {
 		if (ctx->temp)
 			instance->temp_dir = ctx->temp;
-		instance->output_file = strdup(ctx->output);
+		/* The -o could have been done after -B */
+		if (!instance->output_file)
+			instance->output_file = strdup(ctx->output);
 		if (!instance->output_file)
 			die("Failed to allocate output file name for instance");
 		if (!ctx->manual && instance->flags & BUFFER_FL_PROFILE)
-- 
2.43.0


                 reply	other threads:[~2024-01-19 21:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240119162743.1a107fa9@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.