[CRIU] [PATCH v2 48/57] ns: Add usernsd signal handler
Kirill Tkhai
ktkhai at virtuozzo.com
Tue Mar 28 08:41:14 PDT 2017
v2: New
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/namespaces.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 32ef3868..1c19a631 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -14,6 +14,7 @@
#include <limits.h>
#include <errno.h>
#include <sys/ioctl.h>
+#include <sys/ptrace.h>
#include "page.h"
#include "rst-malloc.h"
@@ -24,6 +25,7 @@
#include "mount.h"
#include "pstree.h"
#include "namespaces.h"
+#include "restore.h"
#include "net.h"
#include "cgroup.h"
#include "kerndat.h"
@@ -1511,6 +1513,33 @@ static void unsc_msg_pid_fd(struct unsc_msg *um, pid_t *pid, int *fd)
}
}
+static void usernsd_handler(int signal, siginfo_t *siginfo, void *data)
+{
+ pid_t pid = siginfo->si_pid;
+ int status;
+ int exit;
+
+ if (siginfo->si_code == CLD_TRAPPED && siginfo->si_status == SIGCHLD) {
+ /* The usernsd is ptraced. Allow it to handle SIGCHLD */
+ ptrace(PTRACE_CONT, siginfo->si_pid, 0, SIGCHLD);
+ return;
+ }
+
+ while (pid) {
+ pid = waitpid(-1, &status, WNOHANG);
+ if (pid <= 0)
+ return;
+
+ exit = WIFEXITED(status);
+ status = exit ? WEXITSTATUS(status) : WTERMSIG(status);
+ if (status) {
+ futex_abort_and_wake(&task_entries->nr_in_progress);
+ pr_err("%d finished abnormal\n", pid);
+ } else
+ pr_err("%d exited normally\n", pid);
+ }
+}
+
static int usernsd(int sk)
{
struct sockaddr_un addr;
@@ -1540,6 +1569,11 @@ static int usernsd(int sk)
return -1;
}
+ if (criu_signals_setup(usernsd_handler) < 0) {
+ pr_err("Can't setup handler\n");
+ return -1;
+ }
+
while (1) {
struct unsc_msg um;
static char msg[MAX_UNSFD_MSG_SIZE];
More information about the CRIU
mailing list