[CRIU] [PATCH] parasite: Don't handle CHLD from trapping threads

Pavel Emelyanov xemul at parallels.com
Tue Oct 14 03:20:13 PDT 2014


When dumping threads we do parasite-trap them, instead of running
in daemon mode. While doing this the sigchild handler notices the
CHLD arriving on the thread trap, emits an error

(00.020292) Error (parasite-syscall.c:387): si_code=4 si_pid=3485 si_status=5

but wait() reports -1 (task is not dead, just trapped) and handler
just exits.

Let's not confuse the log readers and just don't notice such CHLDs
at all.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 parasite-syscall.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/parasite-syscall.c b/parasite-syscall.c
index 7cc1a84..e73fe07 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -37,6 +37,16 @@
 #include "asm/dump.h"
 #include "asm/restorer.h"
 
+/*
+ * This is to tell sigchld_handler() that we're trapping a thread.
+ * We don't run this PARASITE_CMD_DUMP_THREAD in daemon mode, instead 
+ * we make it generate the trap, so we need to tell the handler that
+ * it doesn't care about the CHLD arrived -- we will handle errors in
+ * parasite_trap() ourselves.
+ */
+
+static pid_t trapping_tid = 0;
+
 #define parasite_size		(round_up(sizeof(parasite_blob), PAGE_SIZE))
 
 static int can_run_syscall(unsigned long ip, unsigned long start, unsigned long end)
@@ -249,12 +259,16 @@ static int parasite_execute_trap_by_pid(unsigned int cmd,
 
 	*ctl->addr_cmd = cmd;
 
+	trapping_tid = pid;
+
 	ret = parasite_run(pid, PTRACE_CONT, ctl->parasite_ip, stack, &regs, octx);
 	if (ret == 0)
 		ret = parasite_trap(ctl, pid, &regs, octx);
 	if (ret == 0)
 		ret = (int)REG_RES(regs);
 
+	trapping_tid = 0;
+
 	if (ret)
 		pr_err("Parasite exited with %d\n", ret);
 
@@ -379,10 +393,14 @@ int parasite_send_fd(struct parasite_ctl *ctl, int fd)
  * One should use the cr_system helper, that blocks sigcild and waits
  * for the spawned program to finish.
  */
+
 static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
 {
 	int pid, status;
 
+	if (trapping_tid == siginfo->si_pid)
+		return;
+
 	pr_err("si_code=%d si_pid=%d si_status=%d\n",
 		siginfo->si_code, siginfo->si_pid, siginfo->si_status);
 
-- 
1.8.4.2



More information about the CRIU mailing list