Commit c8e6be95 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

restore: create pid namespace

A pid namespace is created if a pid of the first task is 1.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 83e6d14e
...@@ -521,11 +521,20 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone ...@@ -521,11 +521,20 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone
goto err_close; goto err_close;
} }
/* 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))) if (write_img_buf(ca.fd, buf, strlen(buf)))
goto err_unlock; goto err_unlock;
ret = clone(restore_task_with_children, stack + STACK_SIZE, ret = clone(restore_task_with_children, stack + STACK_SIZE,
ns_clone_flags | SIGCHLD, &ca); ca.clone_flags | SIGCHLD, &ca);
if (ret < 0) if (ret < 0)
pr_perror("Can't fork for %d", pid); pr_perror("Can't fork for %d", pid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment