Commit 8fa70268 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Pavel Emelyanov

restore: separate prepare_one_sigaction

Impact: cleaning-up
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 8e606b4d
......@@ -288,40 +288,26 @@ static bool sa_inherited(int sig, rt_sigaction_t *sa)
pa->rt_sa_mask.sig[0] == sa->rt_sa_mask.sig[0];
}
static int prepare_sigactions(void)
/* Returns number of restored signals, -1 or negative errno on fail */
static int restore_one_sigaction(int sig, struct cr_img *img, int pid)
{
int pid = current->pid.virt;
rt_sigaction_t act;
struct cr_img *img;
SaEntry *e;
int sig, rst = 0;
int ret = 0;
if (!task_alive(current))
return 0;
pr_info("Restore sigacts for %d\n", pid);
img = open_image(CR_FD_SIGACT, O_RSTR, pid);
if (!img)
return -1;
for (sig = 1; sig <= SIGMAX; sig++) {
if (sig == SIGKILL || sig == SIGSTOP)
continue;
BUG_ON(sig == SIGKILL || sig == SIGSTOP);
ret = pb_read_one_eof(img, &e, PB_SIGACT);
if (ret == 0) {
if (sig != SIGMAX_OLD + 1) { /* backward compatibility */
pr_err("Unexpected EOF %d\n", sig);
ret = -1;
break;
return -1;
}
pr_warn("This format of sigacts-%d.img is deprecated\n", pid);
break;
return -1;
}
if (ret < 0)
break;
return ret;
ASSIGN_TYPED(act.rt_sa_handler, decode_pointer(e->sigaction));
ASSIGN_TYPED(act.rt_sa_flags, e->flags);
......@@ -332,11 +318,11 @@ static int prepare_sigactions(void)
if (sig == SIGCHLD) {
sigchld_act = act;
continue;
return 0;
}
if (sa_inherited(sig - 1, &act))
continue;
return 1;
/*
* A pure syscall is used, because glibc
......@@ -345,17 +331,44 @@ static int prepare_sigactions(void)
ret = syscall(SYS_rt_sigaction, sig, &act, NULL, sizeof(k_rtsigset_t));
if (ret < 0) {
pr_perror("Can't restore sigaction");
goto err;
return ret;
}
parent_act[sig - 1] = act;
return 1;
}
static int prepare_sigactions(void)
{
int pid = current->pid.virt;
struct cr_img *img;
int sig, rst = 0;
int ret = 0;
if (!task_alive(current))
return 0;
pr_info("Restore sigacts for %d\n", pid);
img = open_image(CR_FD_SIGACT, O_RSTR, pid);
if (!img)
return -1;
for (sig = 1; sig <= SIGMAX; sig++) {
if (sig == SIGKILL || sig == SIGSTOP)
continue;
ret = restore_one_sigaction(sig, img, pid);
if (ret < 0)
break;
if (ret)
rst++;
}
pr_info("Restored %d/%d sigacts\n", rst,
SIGMAX - 3 /* KILL, STOP and CHLD */);
err:
close_image(img);
return ret;
}
......
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