2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

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: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Cyrill Gorcunov
2016-11-23 18:33:56 +03:00
committed by Andrei Vagin
parent 50219defcf
commit 61769b466b

View File

@@ -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;
waitpid(-1, &status, WNOHANG);
/* FIXME -- what to do here? */
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);
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;
}