linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd library; Do not free pthread items from agent
@ 2022-04-06 15:56 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2022-04-06 15:56 UTC (permalink / raw)
  To: Linux Trace Devel

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

The agent creates a tsync to synchronize with the host as well as the host
synchronizing with the guest. The host uses pthread synchronization items
(mutex, cond and barrier) to synchronize its tracing threads as it needs
to retrieve the data that is produced from them.

While debugging the agent, the forked connection would always fail with a
SIGFPE, Arithmetic exception. This was caused by calling
pthread_barrier_destroy() against a barrier that never was initialized.

Since the pthread_mutex, pthread_cond, and pthread_barriers are only
initialized by the host, skip the freeing of them (which both the host and
guest call the same function to free: tracecmd_tsync_free()), if the
guest_id is zero.

Fixes: 3c2d7f97245f1 ("trace-cmd: Wait for first time sync before the trace")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-timesync.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index f8ec15a3fdbc..beaa87d1a065 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -583,9 +583,13 @@ void tracecmd_tsync_free(struct tracecmd_time_sync *tsync)
 	if (tsync->msg_handle)
 		tracecmd_msg_handle_close(tsync->msg_handle);
 
-	pthread_mutex_destroy(&tsync->lock);
-	pthread_cond_destroy(&tsync->cond);
-	pthread_barrier_destroy(&tsync->first_sync);
+	/* These are only created from the host */
+	if (tsync->guest_pid) {
+		pthread_mutex_destroy(&tsync->lock);
+		pthread_cond_destroy(&tsync->cond);
+		pthread_barrier_destroy(&tsync->first_sync);
+	}
+
 	free(tsync->clock_str);
 	free(tsync->proto_name);
 	free(tsync);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-06 17:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-06 15:56 [PATCH] trace-cmd library; Do not free pthread items from agent Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).