mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +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:
committed by
Andrei Vagin
parent
50219defcf
commit
61769b466b
@@ -1017,31 +1017,46 @@ out:
|
|||||||
*/
|
*/
|
||||||
static int make_sock_for(int pid)
|
static int make_sock_for(int pid)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret, mfd, fd, sk = -1;
|
||||||
int mfd, fd;
|
|
||||||
char p[32];
|
char p[32];
|
||||||
|
|
||||||
|
pr_debug("Preparing seqsk for %d\n", pid);
|
||||||
|
|
||||||
sprintf(p, "/proc/%d/ns/net", pid);
|
sprintf(p, "/proc/%d/ns/net", pid);
|
||||||
fd = open(p, O_RDONLY);
|
fd = open(p, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
|
pr_perror("Can't open %p", p);
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
mfd = open("/proc/self/ns/net", O_RDONLY);
|
mfd = open("/proc/self/ns/net", O_RDONLY);
|
||||||
if (mfd < 0)
|
if (mfd < 0) {
|
||||||
|
pr_perror("Can't open self netns");
|
||||||
goto out_c;
|
goto out_c;
|
||||||
|
}
|
||||||
|
|
||||||
if (setns(fd, CLONE_NEWNET))
|
if (setns(fd, CLONE_NEWNET)) {
|
||||||
|
pr_perror("Can't setup target netns");
|
||||||
goto out_cm;
|
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:
|
out_cm:
|
||||||
close(mfd);
|
close(mfd);
|
||||||
out_c:
|
out_c:
|
||||||
close(fd);
|
close(fd);
|
||||||
out:
|
out:
|
||||||
return ret;
|
return sk;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int simple_open_proc(int pid, int mode, const char *fmt, ...)
|
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)
|
static void handle_sigchld(int signal, siginfo_t *siginfo, void *data)
|
||||||
{
|
{
|
||||||
int status;
|
int pid, status;
|
||||||
|
|
||||||
waitpid(-1, &status, WNOHANG);
|
pid = waitpid(-1, &status, WNOHANG);
|
||||||
/* FIXME -- what to do here? */
|
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 {
|
struct plain_regs_struct {
|
||||||
@@ -1151,8 +1181,9 @@ out:
|
|||||||
return ctl;
|
return ctl;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
free(ictx->regs_arg);
|
xfree(ictx->regs_arg);
|
||||||
free(ctl);
|
xfree(ctl);
|
||||||
|
ctl = NULL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user