From ec1de7aeb11456da55b498625b58aa65207fa590 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Fri, 14 Jul 2017 15:40:15 +0300 Subject: [PATCH] pid_ns: Extract functionality of exit of pid_ns helper in function This functionality will be moved in criu task in next patches, the patch is a preparation. v2: Rename the function and move pr_err() to it. Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- criu/include/namespaces.h | 1 + criu/namespaces.c | 33 ++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h index bc7372c22..ef6083c9a 100644 --- a/criu/include/namespaces.h +++ b/criu/include/namespaces.h @@ -283,6 +283,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 void warn_if_pid_ns_helper_exited(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 46d5a5daf..6d962deb9 100644 --- a/criu/namespaces.c +++ b/criu/namespaces.c @@ -1585,29 +1585,36 @@ static void unsc_msg_pid_fd(struct unsc_msg *um, pid_t *pid, int *fd) } } +void warn_if_pid_ns_helper_exited(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; + } + } + + if (ns) + pr_err("Spurious pid ns helper: pid=%d\n", real_pid); +} + 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; - } - } - if (!ns) - pr_err("Spurious pid ns helper: pid=%d\n", pid); + warn_if_pid_ns_helper_exited(pid); pr_err("%d finished unexpected: status=%d\n", pid, status); futex_abort_and_wake(&task_entries->nr_in_progress);