From 184b1d737ca44259ee504db2f29f3cb0d59e4e20 Mon Sep 17 00:00:00 2001 From: "Steven Rostedt (Google)" Date: Fri, 6 Jan 2023 13:39:30 -0500 Subject: trace-cmd record: Keep stopping the recording when finished 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. Link: https://lore.kernel.org/linux-trace-devel/20230106183930.12565-11-rostedt@goodmis.org Signed-off-by: Steven Rostedt (Google) --- tracecmd/trace-record.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index b3614b07..7f0cebe8 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); -- cgit 1.2.3-korg