Commit 3e7627c6 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

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: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 74d1725c
...@@ -111,6 +111,7 @@ struct infect_ctx { ...@@ -111,6 +111,7 @@ struct infect_ctx {
unsigned long flags; /* fine-tune (e.g. faults) */ unsigned long flags; /* fine-tune (e.g. faults) */
void (*child_handler)(int, siginfo_t *, void *); /* hander for SIGCHLD deaths */ void (*child_handler)(int, siginfo_t *, void *); /* hander for SIGCHLD deaths */
struct sigaction orig_handler;
open_proc_fn open_proc; open_proc_fn open_proc;
......
...@@ -384,16 +384,9 @@ static int setup_child_handler(struct parasite_ctl *ctl) ...@@ -384,16 +384,9 @@ static int setup_child_handler(struct parasite_ctl *ctl)
return 0; return 0;
} }
static int restore_child_handler() static int restore_child_handler(struct parasite_ctl *ctl)
{ {
struct sigaction sa = { if (sigaction(SIGCHLD, &ctl->ictx.orig_handler, NULL)) {
.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)) {
pr_perror("Unable to setup SIGCHLD handler"); pr_perror("Unable to setup SIGCHLD handler");
return -1; return -1;
} }
...@@ -1007,6 +1000,14 @@ static int simple_open_proc(int pid, int mode, const char *fmt, ...) ...@@ -1007,6 +1000,14 @@ static int simple_open_proc(int pid, int mode, const char *fmt, ...)
return open(path, mode); 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 *compel_prepare(int pid)
{ {
struct parasite_ctl *ctl; struct parasite_ctl *ctl;
...@@ -1020,6 +1021,9 @@ struct parasite_ctl *compel_prepare(int pid) ...@@ -1020,6 +1021,9 @@ struct parasite_ctl *compel_prepare(int pid)
ictx->task_size = compel_task_size(); ictx->task_size = compel_task_size();
ictx->open_proc = simple_open_proc; ictx->open_proc = simple_open_proc;
ictx->syscall_ip = find_executable_area(pid); 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) if (ictx->syscall_ip == (unsigned long)MAP_FAILED)
goto err; goto err;
ictx->sock = make_sock_for(pid); ictx->sock = make_sock_for(pid);
...@@ -1049,7 +1053,7 @@ static int parasite_fini_seized(struct parasite_ctl *ctl) ...@@ -1049,7 +1053,7 @@ static int parasite_fini_seized(struct parasite_ctl *ctl)
enum trace_flags flag; enum trace_flags flag;
/* stop getting chld from parasite -- we're about to step-by-step it */ /* stop getting chld from parasite -- we're about to step-by-step it */
if (restore_child_handler()) if (restore_child_handler(ctl))
return -1; return -1;
/* Start to trace syscalls for each thread */ /* Start to trace syscalls for each thread */
......
...@@ -581,6 +581,10 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item, ...@@ -581,6 +581,10 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
ictx->open_proc = do_open_proc; ictx->open_proc = do_open_proc;
ictx->child_handler = sigchld_handler; 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->sock = dmpi(item)->netns->net.seqsk;
ictx->save_regs = save_task_regs; ictx->save_regs = save_task_regs;
ictx->make_sigframe = make_sigframe; ictx->make_sigframe = make_sigframe;
......
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