Skip to contentSkip to conversation

trace-cmd: Plug startup race between flush_threads and recorders

PATCH Applied Jan Kiszka 2 participants 2 messages Oct 15, 2010

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 trace-cmd: Plug startup race between flush_threads and recorders

As the SIGUSR1 handler is so far registered after forking the recorder child, there is a small race window where a flush sent by the main process can actually kill the child. Plug this by registering the signal handlers before the fork. This also allows to unify SIGINT registration.

---
 trace-cmd.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
trace-cmd.c +3 -4
index 9cbe362..f8992a8 100644
@@ -1089,6 +1089,8 @@ static int create_recorder(int cpu)
 	char *file;
 	int pid;
 
+	signal(SIGUSR1, flush);
+
 	pid = fork();
 	if (pid < 0)
 		die("fork");
@@ -1096,9 +1098,6 @@ static int create_recorder(int cpu)
 	if (pid)
 		return pid;
 
-	signal(SIGINT, finish);
-	signal(SIGUSR1, flush);
-
 	if (rt_prio)
 		set_prio(rt_prio);
 
@@ -1694,9 +1693,9 @@ int main (int argc, char **argv)
 	set_options();
 
 	if (record || extract) {
+		signal(SIGINT, finish);
 		if (!latency)
 			start_threads();
-		signal(SIGINT, finish);
 	}
 
 	if (extract) {
Signature · 1 line
1.7.1
#1 lore raw
Quoted 6 lines · Jan Kiszka

As the SIGUSR1 handler is so far registered after forking the recorder child, there is a small race window where a flush sent by the main process can actually kill the child. Plug this by registering the signal handlers before the fork. This also allows to unify SIGINT registration.

Applied, Thanks!

-- Steve