[v2,43/57] pid: Save created pid_ns fd to fdstore

Submitted by Kirill Tkhai on March 28, 2017, 3:40 p.m.

Details

Message ID 149071563226.12770.15416004879685296479.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai March 28, 2017, 3:40 p.m.
Save pid_ns of just created pid_ns to fdstore. This will
allow other tasks to get it to create children.

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

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 21d8e813..84e4171b 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1347,8 +1347,9 @@  static int create_children_and_session(void)
 static int restore_task_with_children(void *_arg)
 {
 	struct cr_clone_arg *ca = _arg;
+	struct ns_id *pid_ns;
+	int ret, fd;
 	pid_t pid;
-	int ret;
 
 	current = ca->item;
 
@@ -1443,6 +1444,25 @@  static int restore_task_with_children(void *_arg)
 			goto err;
 	}
 
+	if (ca->clone_flags & CLONE_NEWPID) {
+		pid_ns = lookup_ns_by_id(current->ids->pid_ns_id, &pid_ns_desc);
+		if (!pid_ns) {
+			pr_err("Can't find pid_ns\n");
+			return -1;
+		}
+		fd = open_proc(PROC_SELF, "ns/pid");
+		if (fd < 0) {
+			pr_err("Can't get self pid_ns\n");
+			return -1;
+		}
+		pid_ns->pid.nsfd_id = fdstore_add(fd);
+		close(fd);
+		if (pid_ns->pid.nsfd_id < 0) {
+			pr_err("Can't add fd to fdstore\n");
+			return -1;
+		}
+	}
+
 	if (restore_task_mnt_ns(current))
 		goto err;