diff mbox series

libtracefs: Have echo command concatenate

Message ID 20220201172917.580b9a4f@gandalf.local.home (mailing list archive)
State Accepted
Commit 771893de35cebebf7e2ae9d6962a55849015c280
Headers show
Series libtracefs: Have echo command concatenate | expand

Commit Message

Steven Rostedt Feb. 1, 2022, 10:29 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Currently, tracefs_synth_echo_cmd() does a truncate of the file with the
'>'. This can cause issues if the current files have something already in
it, and could even error with EBUSY if the items can not be deleted.

Use the safer concatenate '>>' instead.

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

Patch

diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index e7dd279ae3f9..aec61ad52e72 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -2196,7 +2196,7 @@  int tracefs_synth_echo_cmd(struct trace_seq *seq,
 	if (!path)
 		goto out_free;
 
-	trace_seq_printf(seq, "echo '%s%s%s %s' > %s/%s\n",
+	trace_seq_printf(seq, "echo '%s%s%s %s' >> %s/%s\n",
 			 synth->dyn_event->prefix,
 			 strlen(synth->dyn_event->prefix) ? ":" : "",
 			 synth->dyn_event->event,
@@ -2211,7 +2211,7 @@  int tracefs_synth_echo_cmd(struct trace_seq *seq,
 	if (!hist)
 		goto out_free;
 
-	trace_seq_printf(seq, "echo '%s' > %s/events/%s/%s/trigger\n",
+	trace_seq_printf(seq, "echo '%s' >> %s/events/%s/%s/trigger\n",
 			 hist, path, synth->start_event->system,
 			 synth->start_event->name);
 	free(hist);
@@ -2221,7 +2221,7 @@  int tracefs_synth_echo_cmd(struct trace_seq *seq,
 	if (!hist)
 		goto out_free;
 
-	trace_seq_printf(seq, "echo '%s' > %s/events/%s/%s/trigger\n",
+	trace_seq_printf(seq, "echo '%s' >> %s/events/%s/%s/trigger\n",
 			 hist, path, synth->end_event->system,
 			 synth->end_event->name);