[v2,04/21] ns: Move forked task user_ns assignment

Submitted by Kirill Tkhai on May 31, 2017, 5:52 p.m.

Details

Message ID 149625313847.18060.15119441696991401626.stgit@localhost.localdomain
State Accepted
Series "Add /proc/[pid]/ns/pid_for_children ns support (and fixes)"
Headers show

Commit Message

Kirill Tkhai May 31, 2017, 5:52 p.m.
Child reaper of a ns have initial user_ns equal to its pid_ns->user_ns.
Keep all ns assignments together.

v2: Delete the assignment from call_clone_fn() and rename patch.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/cr-restore.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 21ba39ec3..06ffe9a8b 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1231,7 +1231,6 @@  static int call_clone_fn(void *arg)
 		return -1;
 	}
 	close(fd);
-	ca->item->user_ns = pid_ns->user_ns;
 
 	if (ca->clone_flags & CLONE_FILES)
 		close_pid_proc();
@@ -1317,15 +1316,18 @@  static inline int fork_with_pid(struct pstree_item *item)
 	pid_t pid = vpid(item);
 	struct ns_id *pid_ns;
 
-	if (item != root_item)
-		item->user_ns = current->user_ns;
-	else
-		item->user_ns = root_user_ns;
-
 	pid_ns = lookup_ns_by_id(item->ids->pid_ns_id, &pid_ns_desc);
 	BUG_ON(!pid_ns);
 	item->pid_for_children_ns = pid_ns;
 
+	if (item != root_item) {
+		if (last_level_pid(item->pid) == INIT_PID)
+			item->user_ns = pid_ns->user_ns;
+		else
+			item->user_ns = current->user_ns;
+	} else
+		item->user_ns = root_user_ns;
+
 	if (item->pid->state != TASK_HELPER) {
 		if (open_core(pid, &ca.core))
 			return -1;