Commit 61769b46 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Andrei Vagin

compel: Improve infect

 - extend handle_sigchld
 - fix garbage return in compel_prepare
 - handle errors in make_sock_for

travis-ci: success for compel: A few fixes and example
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 50219def
......@@ -1017,31 +1017,46 @@ out:
*/
static int make_sock_for(int pid)
{
int ret = -1;
int mfd, fd;
int ret, mfd, fd, sk = -1;
char p[32];
pr_debug("Preparing seqsk for %d\n", pid);
sprintf(p, "/proc/%d/ns/net", pid);
fd = open(p, O_RDONLY);
if (fd < 0)
if (fd < 0) {
pr_perror("Can't open %p", p);
goto out;
}
mfd = open("/proc/self/ns/net", O_RDONLY);
if (mfd < 0)
if (mfd < 0) {
pr_perror("Can't open self netns");
goto out_c;
}
if (setns(fd, CLONE_NEWNET))
if (setns(fd, CLONE_NEWNET)) {
pr_perror("Can't setup target netns");
goto out_cm;
}
ret = socket(PF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK, 0);
sk = socket(PF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK, 0);
if (sk < 0)
pr_perror("Can't create seqsk");
setns(mfd, CLONE_NEWNET);
ret = setns(mfd, CLONE_NEWNET);
if (ret) {
pr_perror("Can't restore former netns");
if (sk >= 0)
close(sk);
sk = -1;
}
out_cm:
close(mfd);
out_c:
close(fd);
out:
return ret;
return sk;
}
static int simple_open_proc(int pid, int mode, const char *fmt, ...)
......@@ -1061,10 +1076,25 @@ static int simple_open_proc(int pid, int mode, const char *fmt, ...)
static void handle_sigchld(int signal, siginfo_t *siginfo, void *data)
{
int status;
int pid, status;
pid = waitpid(-1, &status, WNOHANG);
if (pid <= 0)
return;
pr_err("si_code=%d si_pid=%d si_status=%d\n",
siginfo->si_code, siginfo->si_pid, siginfo->si_status);
waitpid(-1, &status, WNOHANG);
/* FIXME -- what to do here? */
if (WIFEXITED(status))
pr_err("%d exited with %d unexpectedly\n", pid, WEXITSTATUS(status));
else if (WIFSIGNALED(status))
pr_err("%d was killed by %d unexpectedly: %s\n",
pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
else if (WIFSTOPPED(status))
pr_err("%d was stopped by %d unexpectedly\n", pid, WSTOPSIG(status));
/* FIXME Should we exit? */
/* exit(1); */
}
struct plain_regs_struct {
......@@ -1151,8 +1181,9 @@ out:
return ctl;
err:
free(ictx->regs_arg);
free(ctl);
xfree(ictx->regs_arg);
xfree(ctl);
ctl = NULL;
goto out;
}
......
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