2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00

compel: Handle sigchilds in compel

CRIU sets up a child hander to get errors from tasks it
infects. For compel we'd have the same problem, so there's
a way to request for custom child handler, but compel
should provide some default by himself. And it's not clear
atm how this should look like, so here's a plain stub to
move forward.

travis-ci: success for compel: Contrinue improving library
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Pavel Emelyanov
2016-11-21 21:26:17 +03:00
committed by Andrei Vagin
parent 74d1725ca0
commit 3e7627c6ac
3 changed files with 19 additions and 10 deletions

View File

@@ -111,6 +111,7 @@ struct infect_ctx {
unsigned long flags; /* fine-tune (e.g. faults) */
void (*child_handler)(int, siginfo_t *, void *); /* hander for SIGCHLD deaths */
struct sigaction orig_handler;
open_proc_fn open_proc;

View File

@@ -384,16 +384,9 @@ static int setup_child_handler(struct parasite_ctl *ctl)
return 0;
}
static int restore_child_handler()
static int restore_child_handler(struct parasite_ctl *ctl)
{
struct sigaction sa = {
.sa_handler = SIG_DFL, /* XXX -- should be original? */
.sa_flags = SA_SIGINFO | SA_RESTART,
};
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGCHLD);
if (sigaction(SIGCHLD, &sa, NULL)) {
if (sigaction(SIGCHLD, &ctl->ictx.orig_handler, NULL)) {
pr_perror("Unable to setup SIGCHLD handler");
return -1;
}
@@ -1007,6 +1000,14 @@ static int simple_open_proc(int pid, int mode, const char *fmt, ...)
return open(path, mode);
}
static void handle_sigchld(int signal, siginfo_t *siginfo, void *data)
{
int status;
waitpid(-1, &status, WNOHANG);
/* FIXME -- what to do here? */
}
struct parasite_ctl *compel_prepare(int pid)
{
struct parasite_ctl *ctl;
@@ -1020,6 +1021,9 @@ struct parasite_ctl *compel_prepare(int pid)
ictx->task_size = compel_task_size();
ictx->open_proc = simple_open_proc;
ictx->syscall_ip = find_executable_area(pid);
ictx->child_handler = handle_sigchld;
sigaction(SIGCHLD, NULL, &ictx->orig_handler);
if (ictx->syscall_ip == (unsigned long)MAP_FAILED)
goto err;
ictx->sock = make_sock_for(pid);
@@ -1049,7 +1053,7 @@ static int parasite_fini_seized(struct parasite_ctl *ctl)
enum trace_flags flag;
/* stop getting chld from parasite -- we're about to step-by-step it */
if (restore_child_handler())
if (restore_child_handler(ctl))
return -1;
/* Start to trace syscalls for each thread */

View File

@@ -581,6 +581,10 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
ictx->open_proc = do_open_proc;
ictx->child_handler = sigchld_handler;
ictx->orig_handler.sa_handler = SIG_DFL;
ictx->orig_handler.sa_flags = SA_SIGINFO | SA_RESTART;
sigemptyset(&ictx->orig_handler.sa_mask);
sigaddset(&ictx->orig_handler.sa_mask, SIGCHLD);
ictx->sock = dmpi(item)->netns->net.seqsk;
ictx->save_regs = save_task_regs;
ictx->make_sigframe = make_sigframe;