[CRIU] [PATCH 2/3] restore: Restore SIGSEGV sigaction later

Kirill Tkhai ktkhai at virtuozzo.com
Mon May 29 07:01:50 PDT 2017


Do it later, and this allows to set criu own handler for SIGSEGV.
It will be used to print stack trace in next patch.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-restore.c       |   14 ++++++++++++++
 criu/include/restorer.h |    1 +
 criu/pie/restorer.c     |    4 ++++
 3 files changed, 19 insertions(+)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 21ba39ec3..a420f77af 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -460,6 +460,7 @@ static int set_pid_ns_for_children(struct ns_id *pid_ns, struct pid *pid)
 }
 
 static rt_sigaction_t sigchld_act;
+static rt_sigaction_t sigsegv_act;
 /*
  * If parent's sigaction has blocked SIGKILL (which is non-sence),
  * this parent action is non-valid and shouldn't be inherited.
@@ -508,6 +509,10 @@ static int restore_native_sigaction(int sig, SaEntry *e)
 		sigchld_act = act;
 		return 0;
 	}
+	if (sig == SIGSEGV) {
+		sigsegv_act = act;
+		return 0;
+	}
 
 	if (sa_inherited(sig - 1, &act))
 		return 1;
@@ -572,6 +577,10 @@ static int restore_compat_sigaction(int sig, SaEntry *e)
 		memcpy(&sigchld_act, &act, sizeof(rt_sigaction_t_compat));
 		return 0;
 	}
+	if (sig == SIGSEGV) {
+		memcpy(&sigsegv_act, &act, sizeof(rt_sigaction_t_compat));
+		return 0;
+	}
 
 	if (sa_compat_inherited(sig - 1, &act))
 		return 1;
@@ -1069,6 +1078,10 @@ static int restore_one_zombie(CoreEntry *core)
 			signr = SIGABRT;
 		}
 
+		if (signr == SIGSEGV)
+			syscall(SYS_rt_sigaction, signr, &sigsegv_act,
+				NULL, sizeof(k_rtsigset_t));
+
 		if (kill(last_level_pid(current->pid), signr) < 0)
 			pr_perror("Can't kill myself, will just exit");
 
@@ -3425,6 +3438,7 @@ static int sigreturn_restore(pid_t pid, struct task_restore_args *task_args, uns
 	task_args->loglevel	= log_get_loglevel();
 	log_get_logstart(&task_args->logstart);
 	task_args->sigchld_act	= sigchld_act;
+	task_args->sigsegv_act	= sigsegv_act;
 
 	strncpy(task_args->comm, core->tc->comm, sizeof(task_args->comm));
 	pid_ns = lookup_ns_by_id(current->ids->pid_ns_id, &pid_ns_desc);
diff --git a/criu/include/restorer.h b/criu/include/restorer.h
index 1866bbd82..cfee03bd7 100644
--- a/criu/include/restorer.h
+++ b/criu/include/restorer.h
@@ -169,6 +169,7 @@ struct task_restore_args {
 	unsigned long			premmapped_addr;
 	unsigned long			premmapped_len;
 	rt_sigaction_t			sigchld_act;
+	rt_sigaction_t			sigsegv_act;
 
 	void				*bootstrap_start;
 	unsigned long			bootstrap_len;
diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c
index 736c12504..0f61c4b98 100644
--- a/criu/pie/restorer.c
+++ b/criu/pie/restorer.c
@@ -1582,6 +1582,8 @@ long __export_restore_task(struct task_restore_args *args)
 	if (!args->compatible_mode) {
 		sys_sigaction(SIGCHLD, &args->sigchld_act,
 				NULL, sizeof(k_rtsigset_t));
+		sys_sigaction(SIGSEGV, &args->sigsegv_act,
+				NULL, sizeof(k_rtsigset_t));
 	} else {
 		void *stack = alloc_compat_syscall_stack();
 
@@ -1591,6 +1593,8 @@ long __export_restore_task(struct task_restore_args *args)
 		}
 		arch_compat_rt_sigaction(stack, SIGCHLD,
 				(void*)&args->sigchld_act);
+		arch_compat_rt_sigaction(stack, SIGSEGV,
+				(void*)&args->sigsegv_act);
 		free_compat_syscall_stack(stack);
 	}
 



More information about the CRIU mailing list