diff mbox series

[10/10] trace-cmd record: Keep stopping the recording when finished

Message ID 20230106183930.12565-11-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 184b1d737ca44259ee504db2f29f3cb0d59e4e20
Headers show
Series trace-cmd: Fix trace-cmd stream | expand

Commit Message

Steven Rostedt Jan. 6, 2023, 6:39 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The tracecmd_stop_recording() is suppose to force the recorders to finish,
but because it is called from a signal handler, that may not necessarily be
the case (due to race conditions and such). Set an alarm to try again in a
second, then after two seconds, and then three, and so on.

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

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index b3614b0706de..7f0cebe8cd7a 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3164,11 +3164,21 @@  static void expand_event_list(void)
 
 static void finish(void)
 {
+	static int secs = 1;
+
 	sleep_time = 0;
 
 	/* all done */
-	if (recorder)
+	if (recorder) {
 		tracecmd_stop_recording(recorder);
+		/*
+		 * We could just call the alarm if the above returned non zero,
+		 * as zero is suppose to guarantee that the reader woke up.
+		 * But as this is called from a signal handler, that may not
+		 * necessarily be the case.
+		 */
+		alarm(secs++);
+	}
 	finished = 1;
 }
 
@@ -3181,6 +3191,7 @@  static void flush(void)
 static void do_sig(int sig)
 {
 	switch (sig) {
+	case SIGALRM:
 	case SIGUSR1:
 	case SIGINT:
 		return finish();
@@ -3432,6 +3443,7 @@  static int create_recorder(struct buffer_instance *instance, int cpu,
 		signal(SIGINT, SIG_IGN);
 		signal(SIGUSR1, do_sig);
 		signal(SIGUSR2, do_sig);
+		signal(SIGALRM, do_sig);
 
 		if (rt_prio)
 			set_prio(rt_prio);