[CRIU] [PATCH RESEND v1 48/55] pid: Wait till pid_ns created before we create a child of this ns

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 24 08:16:34 PDT 2017


If we are not creating a pid_ns, we need to wait while it's not
created by parent of the ns's INIT_PID.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-restore.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c3915ff0..3245629d 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -310,6 +310,20 @@ static int set_next_pid(struct ns_id *ns, struct pid *pid)
 	return __set_next_pid(pid->ns[0].virt);
 }
 
+static void wait_pid_ns_helper_prepared(struct ns_id *pid_ns, struct pid *pid)
+{
+	if (!(root_ns_mask & CLONE_NEWPID))
+		return;
+
+	if (last_level_pid(pid) == INIT_PID) {
+		pid_ns = pid_ns->parent;
+		if (!pid_ns)
+			return;
+	}
+
+	futex_wait_while_eq(&pid_ns->pid.helper_created, 0);
+}
+
 static rt_sigaction_t sigchld_act;
 /*
  * If parent's sigaction has blocked SIGKILL (which is non-sence),
@@ -1057,6 +1071,8 @@ static inline int fork_with_pid(struct pstree_item *item)
 	if (ca.fd < 0)
 		goto err;
 
+	wait_pid_ns_helper_prepared(pid_ns, item->pid);
+
 	if (flock(ca.fd, LOCK_EX)) {
 		pr_perror("%d: Can't lock %s", pid, LAST_PID_PATH);
 		goto err_close;



More information about the CRIU mailing list