Commit ced9c529 authored by Tycho Andersen's avatar Tycho Andersen Committed by Pavel Emelyanov

restore: fix race with helpers' kids dying too early

We masked off SIGCHLD in wait_on_helpers_zombies(), but in fact this is too
late: zombies can die any time after CR_STATE_RESTORE before this function
is called, which lead to us getting "unexpected" deaths. Instead, we should
mask off SIGCHLD before the helpers finish CR_STATE_RESTORE, since they're
explicitly going to wait on all their kids to make sure they don't die
anyway.
Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Acked-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent dfe5f4e5
......@@ -639,15 +639,6 @@ static unsigned long task_entries_pos;
static int wait_on_helpers_zombies(void)
{
struct pstree_item *pi;
sigset_t blockmask, oldmask;
sigemptyset(&blockmask);
sigaddset(&blockmask, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &blockmask, &oldmask) == -1) {
pr_perror("Can not set mask of blocked signals");
return -1;
}
list_for_each_entry(pi, &current->children, sibling) {
pid_t pid = pi->pid.virt;
......@@ -669,11 +660,6 @@ static int wait_on_helpers_zombies(void)
}
}
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) == -1) {
pr_perror("Can not unset mask of blocked signals");
BUG();
}
return 0;
}
......@@ -761,6 +747,16 @@ static int restore_one_task(int pid, CoreEntry *core)
else if (current->pid.state == TASK_DEAD)
ret = restore_one_zombie(core);
else if (current->pid.state == TASK_HELPER) {
sigset_t blockmask, oldmask;
sigemptyset(&blockmask);
sigaddset(&blockmask, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &blockmask, &oldmask) == -1) {
pr_perror("Can not set mask of blocked signals");
return -1;
}
restore_finish_stage(CR_STATE_RESTORE);
if (wait_on_helpers_zombies()) {
pr_err("failed to wait on helpers and zombies\n");
......
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