[CRIU] [PATCH 6/7] crtools: restore pending signals
Andrey Vagin
avagin at openvz.org
Tue Dec 4 04:50:30 EST 2012
Only shared signals are restored by now
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
cr-restore.c | 6 ++++++
include/restorer.h | 1 +
pie/restorer.c | 41 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/cr-restore.c b/cr-restore.c
index 78ee82d..9cf328e 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1719,6 +1719,12 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
task_args = mem;
thread_args = mem + restore_task_vma_len;
+ task_args->signal_img_fd = open_image_ro(CR_FD_SIGNAL, pid);
+ if (task_args->signal_img_fd < 0) {
+ if (errno != ENOENT) /* backward compatiblity */
+ goto err;
+ }
+
/*
* Adjust stack.
*/
diff --git a/include/restorer.h b/include/restorer.h
index e4332a0..650f8b1 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -86,6 +86,7 @@ struct task_restore_core_args {
int fd_exe_link; /* opened self->exe file */
int logfd;
+ int signal_img_fd;
unsigned int loglevel;
mutex_t rst_lock;
diff --git a/pie/restorer.c b/pie/restorer.c
index 95dca19..5a02573 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -400,6 +400,40 @@ static int vma_remap(unsigned long src, unsigned long dst, unsigned long len)
return 0;
}
+static int restore_signals(struct task_restore_core_args *args)
+{
+ int ret;
+ k_rtsigset_t to_block;
+
+ ksigfillset(&to_block);
+ ret = sys_sigprocmask(SIG_SETMASK, &to_block, NULL, sizeof(k_rtsigset_t));
+ if (ret) {
+ pr_err("Unable to block signals %d", ret);
+ return -1;
+ }
+
+ while (1) {
+ siginfo_t info;
+
+ ret = sys_read(args->signal_img_fd, &info, sizeof(info));
+ if (ret == 0)
+ break;
+ if (ret < 0) {
+ pr_err("read() failed with code %d\n", ret);
+ return -1;
+ }
+ ret = sys_rt_sigqueueinfo(sys_getpid(), info.si_signo, &info);
+ if (ret) {
+ pr_err("Unable to send siginfo %d %x with code %d\n",
+ info.si_signo, info.si_code, ret);
+ return -1;;
+ }
+ }
+
+ sys_close(args->signal_img_fd);
+
+ return 0;
+}
/*
* The main routine to restore task via sigreturn.
* This one is very special, we never return there
@@ -752,6 +786,12 @@ long __export_restore_task(struct task_restore_core_args *args)
sys_sigaction(SIGCHLD, &args->sigchld_act, NULL, sizeof(rt_sigset_t));
+ if (args->signal_img_fd >= 0) {
+ ret = restore_signals(args);
+ if (ret)
+ goto core_restore_end;
+ }
+
futex_set_and_wake(&thread_inprogress, args->nr_threads);
futex_dec_and_wake(&args->task_entries->nr_in_progress);
@@ -807,6 +847,7 @@ long __export_restore_task(struct task_restore_core_args *args)
: "rax","rsp","memory");
core_restore_end:
+ futex_abort_and_wake(&task_entries->nr_in_progress);
pr_err("Restorer fail %ld\n", sys_getpid());
sys_exit_group(1);
return -1;
--
1.7.11.7
More information about the CRIU
mailing list