Commit 74d1725c authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

compel: Create socket for pid

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.

travis-ci: success for compel: Contrinue improving library
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent e50235b6
......@@ -959,6 +959,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;
......@@ -989,6 +1022,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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment