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

Andrey Vagin avagin at openvz.org
Thu Aug 15 10:57:08 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.

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

diff --git a/cr-restore.c b/cr-restore.c
index 3161531..a6273f9 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -933,8 +933,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);
@@ -1358,8 +1362,8 @@ out:
 				kill(root_item->pid.real, SIGKILL);
 		} else {
 			for_each_pstree_item(pi)
-				if (pi->pid.virt > 0)
-					kill(pi->pid.virt, SIGKILL);
+				if (pi->pid.real > 0)
+					kill(pi->pid.real, SIGKILL);
 		}
 
 		pr_err("Restoring FAILED.\n");
-- 
1.8.3.1



More information about the CRIU mailing list