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) ...@@ -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]; 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; rt_sigaction_t act;
struct cr_img *img;
SaEntry *e; SaEntry *e;
int sig, rst = 0;
int ret = 0; int ret = 0;
if (!task_alive(current)) BUG_ON(sig == SIGKILL || sig == SIGSTOP);
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 = pb_read_one_eof(img, &e, PB_SIGACT); ret = pb_read_one_eof(img, &e, PB_SIGACT);
if (ret == 0) { if (ret == 0) {
if (sig != SIGMAX_OLD + 1) { /* backward compatibility */ if (sig != SIGMAX_OLD + 1) { /* backward compatibility */
pr_err("Unexpected EOF %d\n", sig); pr_err("Unexpected EOF %d\n", sig);
ret = -1; return -1;
break;
} }
pr_warn("This format of sigacts-%d.img is deprecated\n", pid); pr_warn("This format of sigacts-%d.img is deprecated\n", pid);
break; return -1;
} }
if (ret < 0) if (ret < 0)
break; return ret;
ASSIGN_TYPED(act.rt_sa_handler, decode_pointer(e->sigaction)); ASSIGN_TYPED(act.rt_sa_handler, decode_pointer(e->sigaction));
ASSIGN_TYPED(act.rt_sa_flags, e->flags); ASSIGN_TYPED(act.rt_sa_flags, e->flags);
...@@ -332,11 +318,11 @@ static int prepare_sigactions(void) ...@@ -332,11 +318,11 @@ static int prepare_sigactions(void)
if (sig == SIGCHLD) { if (sig == SIGCHLD) {
sigchld_act = act; sigchld_act = act;
continue; return 0;
} }
if (sa_inherited(sig - 1, &act)) if (sa_inherited(sig - 1, &act))
continue; return 1;
/* /*
* A pure syscall is used, because glibc * A pure syscall is used, because glibc
...@@ -345,17 +331,44 @@ static int prepare_sigactions(void) ...@@ -345,17 +331,44 @@ static int prepare_sigactions(void)
ret = syscall(SYS_rt_sigaction, sig, &act, NULL, sizeof(k_rtsigset_t)); ret = syscall(SYS_rt_sigaction, sig, &act, NULL, sizeof(k_rtsigset_t));
if (ret < 0) { if (ret < 0) {
pr_perror("Can't restore sigaction"); pr_perror("Can't restore sigaction");
goto err; return ret;
} }
parent_act[sig - 1] = act; 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++; rst++;
} }
pr_info("Restored %d/%d sigacts\n", rst, pr_info("Restored %d/%d sigacts\n", rst,
SIGMAX - 3 /* KILL, STOP and CHLD */); SIGMAX - 3 /* KILL, STOP and CHLD */);
err:
close_image(img); close_image(img);
return ret; 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