[CRIU] [PATCH] crtools: don't kill processes which were created by someone else (v2)

Andrey Vagin avagin at openvz.org
Thu Aug 15 11:11:36 EDT 2013


Currently if criu forked a process and its pid doesn't match required
one, criu enumirates all task entries and kills processes by pid from
these entries.

A part of processes can not be forked yet and one proccess is forked
with wrong pid, so criu kills minimum one wrong process.

v2: rebase on top of the current HEAD

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index b899eb9..1bd8721 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -929,8 +929,12 @@ static inline int fork_with_pid(struct pstree_item *item)
 	if (ret < 0)
 		pr_perror("Can't fork for %d", pid);
 
-	if (ca.clone_flags & CLONE_NEWPID)
-		item->pid.real = ret;
+	if (!(ca.clone_flags & CLONE_NEWPID) && ret != pid) {
+		pr_err("Pid %d do not match expected %d\n", ret, pid);
+		return -1;
+	}
+
+	item->pid.real = ret;
 
 	if (opts.pidfile && root_item == item)
 		write_pidfile(opts.pidfile, ret);
@@ -1374,7 +1378,7 @@ out:
 
 		for_each_pstree_item(pi)
 			if (pi->pid.virt > 0)
-				kill(pi->pid.virt, SIGKILL);
+				kill(pi->pid.real, SIGKILL);
 	}
 
 	pr_err("Restoring FAILED.\n");
-- 
1.8.3.1



More information about the CRIU mailing list