[CRIU] [PATCH v4 31/41] ns: Add usernsd signal handler

Kirill Tkhai ktkhai at virtuozzo.com
Thu May 4 09:10:26 PDT 2017


Handler to catch exited children of usernsd.
This will be used in next patches to watch
for pid_ns helpers exit.

v4: Do not watch for CLD_TRAPPED, as it's need only for root_item
v3: pr_err() -> pr_info()
v2: New

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/namespaces.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 3562f9a2a..97ea2b0e6 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"
@@ -1508,6 +1510,27 @@ 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;
+
+	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_info("%d exited normally\n", pid);
+	}
+}
+
 static int usernsd(int sk)
 {
 	struct sockaddr_un addr;
@@ -1537,6 +1560,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