[CRIU] [PATCH 4/8] compel: Create socket for pid

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 21 10:26:16 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

Compel needs a socket that lives in victim's net namespace.
CRIU creates this socket once for all the processes it works
with. For pure compel case the socket is created for each
new ctl.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 compel/src/lib/infect.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
index a834f76b6fb9..20688af265ba 100644
--- a/compel/src/lib/infect.c
+++ b/compel/src/lib/infect.c
@@ -961,6 +961,39 @@ out:
 	return ret;
 }
 
+/*
+ * This routine is to create PF_UNIX/SOCK_SEQPACKET socket
+ * in the target net namespace
+ */
+static int make_sock_for(int pid)
+{
+	int ret = -1;
+	int mfd, fd;
+	char p[32];
+
+	sprintf(p, "/proc/%d/ns/net", pid);
+	fd = open(p, O_RDONLY);
+	if (fd < 0)
+		goto out;
+
+	mfd = open("/proc/self/ns/net", O_RDONLY);
+	if (mfd < 0)
+		goto out_c;
+
+	if (setns(fd, CLONE_NEWNET))
+		goto out_cm;
+
+	ret = socket(PF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK, 0);
+
+	setns(mfd, CLONE_NEWNET);
+out_cm:
+	close(mfd);
+out_c:
+	close(fd);
+out:
+	return ret;
+}
+
 static int simple_open_proc(int pid, int mode, const char *fmt, ...)
 {
 	int l;
@@ -991,6 +1024,9 @@ struct parasite_ctl *compel_prepare(int pid)
 	ictx->syscall_ip = find_executable_area(pid);
 	if (ictx->syscall_ip == (unsigned long)MAP_FAILED)
 		goto err;
+	ictx->sock = make_sock_for(pid);
+	if (ictx->sock < 0)
+		goto err;
 
 out:
 	return ctl;
-- 
2.7.4



More information about the CRIU mailing list