[CRIU] [PATCH REBASED 1/3] pid_ns: Extract functionality of exit of pid_ns helper in function

Kirill Tkhai ktkhai at virtuozzo.com
Thu Jul 6 14:13:21 MSK 2017


This functionality will be moved in criu task in next patches,
the patch is a preparation.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/namespaces.h |    1 +
 criu/namespaces.c         |   29 +++++++++++++++++++----------
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 44520a81a..8aa25a95e 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -278,6 +278,7 @@ static inline int pid_ns_root_off(void)
 extern int reserve_pid_ns_helpers(void);
 extern int create_pid_ns_helper(struct ns_id *ns);
 extern int destroy_pid_ns_helpers(void);
+extern struct ns_id *handle_pid_ns_helper_exit(pid_t real_pid);
 extern int request_set_next_pid(int pid_ns_id, pid_t pid, int sk);
 
 #endif /* __CR_NS_H__ */
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 100a631e9..674b43820 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -1585,27 +1585,36 @@ static void unsc_msg_pid_fd(struct unsc_msg *um, pid_t *pid, int *fd)
 	}
 }
 
+struct ns_id *handle_pid_ns_helper_exit(pid_t real_pid)
+{
+	struct ns_id *ns;
+	struct pid *pid;
+
+	for (ns = ns_ids; ns; ns = ns->next) {
+		if (ns->nd != &pid_ns_desc)
+			continue;
+		pid = __pstree_pid_by_virt(ns, ns->ns_pid);
+		if (pid->real == real_pid) {
+			pid->real = -1;
+			break;
+		}
+	}
+
+	return ns;
+}
+
 static void usernsd_handler(int signal, siginfo_t *siginfo, void *data)
 {
 	pid_t pid = siginfo->si_pid;
 	struct ns_id *ns;
-	struct pid *tpid;
 	int status;
 
 	while (pid) {
 		pid = waitpid(-1, &status, WNOHANG);
 		if (pid <= 0)
 			return;
-		for (ns = ns_ids; ns; ns = ns->next) {
-			if (ns->nd != &pid_ns_desc)
-				continue;
-			tpid = __pstree_pid_by_virt(ns, ns->ns_pid);
-			if (tpid->real == pid) {
-				tpid->real = -1;
-				break;
-			}
-		}
 
+		ns = handle_pid_ns_helper_exit(pid);
 		if (!ns)
 			pr_err("Spurious pid ns helper: pid=%d\n", pid);
 



More information about the CRIU mailing list