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

Kirill Tkhai ktkhai at virtuozzo.com
Tue Mar 28 08:40:32 PDT 2017


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 at virtuozzo.com>
---
 criu/cr-restore.c |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

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;
 



More information about the CRIU mailing list