[v2,17/21] fork: Move ns-specific code to setup_child_task_namespaces()

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

Details

Message ID 149625327221.18060.12385608612126695515.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:54 p.m.
No functional changes -- just to improve readability.

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

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index cac963dce..70d369ada 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -459,6 +459,32 @@  static int set_pid_ns_for_children(struct ns_id *pid_ns, struct pid *pid)
 	return ret;
 }
 
+static int setup_child_task_namespaces(struct pstree_item *item, struct ns_id **ret_pid_ns)
+{
+	struct ns_id *pid_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;
+
+	wait_pid_ns_helper_prepared(pid_ns, item->pid);
+
+	if (set_pid_ns_for_children(pid_ns, item->pid) < 0)
+		return -1;
+
+	*ret_pid_ns = pid_ns;
+
+	return 0;
+}
+
 static rt_sigaction_t sigchld_act;
 /*
  * If parent's sigaction has blocked SIGKILL (which is non-sence),
@@ -1330,18 +1356,6 @@  static inline int fork_with_pid(struct pstree_item *item)
 	pid_t pid = vpid(item);
 	struct ns_id *pid_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;
@@ -1380,9 +1394,7 @@  static inline int fork_with_pid(struct pstree_item *item)
 
 	pr_info("Forking task with %d pid (flags 0x%lx)\n", pid, ca.clone_flags);
 
-	wait_pid_ns_helper_prepared(pid_ns, item->pid);
-
-	if (set_pid_ns_for_children(pid_ns, item->pid) < 0)
+	if (setup_child_task_namespaces(item, &pid_ns))
 		goto err;
 
 	lock_last_pid();