[CRIU] [PATCH 3/6] restore: use signals_s and signals_p to prepare signals
Ruslan Kuprieiev
kupruser at gmail.com
Fri Aug 15 06:02:15 PDT 2014
In order to save backward compatibility, criu will try to open signal*.img,
if no signals_* are found.
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
cr-restore.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 46 insertions(+), 14 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index d3c7b0b..7a154d7 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -91,7 +91,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core);
static int prepare_restorer_blob(void);
static int prepare_rlimits(int pid, CoreEntry *core);
static int prepare_posix_timers(int pid, CoreEntry *core);
-static int prepare_signals(int pid);
+static int prepare_signals(int pid, CoreEntry *core);
static int root_as_sibling;
@@ -795,7 +795,7 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
if (open_cores(pid, core))
return -1;
- if (prepare_signals(pid))
+ if (prepare_signals(pid, core))
return -1;
if (prepare_posix_timers(pid, core))
@@ -2380,6 +2380,20 @@ static int prepare_rlimits(int pid, CoreEntry *core)
return 0;
}
+static int signal_to_mem(SiginfoEntry *sie)
+{
+ siginfo_t *info, *t;
+
+ info = (siginfo_t *) sie->siginfo.data;
+ t = rst_mem_alloc(sizeof(siginfo_t), RM_PRIVATE);
+ if (!t)
+ return -1;
+
+ memcpy(t, info, sizeof(*info));
+
+ return 0;
+}
+
static int open_signal_image(int type, pid_t pid, unsigned int *nr)
{
int fd, ret;
@@ -2395,7 +2409,6 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr)
*nr = 0;
while (1) {
SiginfoEntry *sie;
- siginfo_t *info, *t;
ret = pb_read_one_eof(fd, &sie, PB_SIGINFO);
if (ret <= 0)
@@ -2405,14 +2418,11 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr)
ret = -1;
break;
}
- info = (siginfo_t *) sie->siginfo.data;
- t = rst_mem_alloc(sizeof(siginfo_t), RM_PRIVATE);
- if (!t) {
- ret = -1;
- break;
- }
- memcpy(t, info, sizeof(*info));
+ ret = signal_to_mem(sie);
+ if (ret)
+ break;
+
(*nr)++;
siginfo_entry__free_unpacked(sie, NULL);
@@ -2423,10 +2433,23 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr)
return ret ? : 0;
}
+static int prepare_one_signal_queue(SignalQueueEntry *sqe, unsigned int *nr)
+{
+ int i;
+
+ for (i = 0; i < sqe->n_signals; i++)
+ if (signal_to_mem(sqe->signals[i]))
+ return -1;
+
+ *nr = sqe->n_signals;
+
+ return 0;
+}
+
static unsigned long siginfo_cpos;
static unsigned int siginfo_nr, *siginfo_priv_nr;
-static int prepare_signals(int pid)
+static int prepare_signals(int pid, CoreEntry *leader_core)
{
int ret = -1, i;
@@ -2435,13 +2458,22 @@ static int prepare_signals(int pid)
if (siginfo_priv_nr == NULL)
goto out;
- ret = open_signal_image(CR_FD_SIGNAL, pid, &siginfo_nr);
+ /* Prepare shared signals */
+ if (!leader_core->tc->signals_s)/*backward compatibility*/
+ ret = open_signal_image(CR_FD_SIGNAL, pid, &siginfo_nr);
+ else
+ ret = prepare_one_signal_queue(leader_core->tc->signals_s, &siginfo_nr);
+
if (ret < 0)
goto out;
for (i = 0; i < current->nr_threads; i++) {
- ret = open_signal_image(CR_FD_PSIGNAL,
- current->threads[i].virt, &siginfo_priv_nr[i]);
+ if (!current->core[i]->thread_core->signals_p)/*backward compatibility*/
+ ret = open_signal_image(CR_FD_PSIGNAL,
+ current->threads[i].virt, &siginfo_priv_nr[i]);
+ else
+ ret = prepare_one_signal_queue(current->core[i]->thread_core->signals_p,
+ &siginfo_priv_nr[i]);
if (ret < 0)
goto out;
}
--
1.9.1
More information about the CRIU
mailing list