[CRIU] [PATCH cr 04/13] restore: create pid namespace

Andrey Vagin avagin at openvz.org
Tue Jun 19 07:53:08 EDT 2012


A pid namespace is created if a pid of the first task is 1.

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

diff --git a/cr-restore.c b/cr-restore.c
index 1eb1226..7c359c9 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -521,11 +521,20 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone
 		goto err_close;
 	}
 
-	if (write_img_buf(ca.fd, buf, strlen(buf)))
-		goto err_unlock;
+	/* A process with pid = 1 is "init". It should be restore in new pid ns.
+	 * The first process in pid ns gets pid = 1 automaticaly. */
+	if (pid == 1) {
+		ca.clone_flags |= CLONE_NEWPID;
+		if (item != root_item) {
+			pr_err("Only first task can have pid = 1");
+			goto err_unlock;
+		}
+	} else
+		if (write_img_buf(ca.fd, buf, strlen(buf)))
+			goto err_unlock;
 
 	ret = clone(restore_task_with_children, stack + STACK_SIZE,
-			ns_clone_flags | SIGCHLD, &ca);
+			ca.clone_flags | SIGCHLD, &ca);
 
 	if (ret < 0)
 		pr_perror("Can't fork for %d", pid);
-- 
1.7.1



More information about the CRIU mailing list