From 6f4a4e1bbd5e1ad0f5ba769ee6cdd7da1efde741 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Wed, 31 May 2017 20:52:48 +0300 Subject: [PATCH] dump: More obvious assignment of top_pid_ns Currently it's set in generate_ns_id() and it's equal to: 1)NS_CRIU, if root_ns_mask does not contain CLONE_NEWPID, 2)NS_ROOT, if it contains. The assignment is not obvious, as it's set NS_CRIU firstly, and then rewrites in NS_ROOT, if it exists. Mark top_pid_ns after ns_ids population in more clear way. Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- criu/cr-dump.c | 27 +++++++++++++++++++++++++-- criu/namespaces.c | 5 +---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/criu/cr-dump.c b/criu/cr-dump.c index bbb265005..7c9270110 100644 --- a/criu/cr-dump.c +++ b/criu/cr-dump.c @@ -822,6 +822,29 @@ static int predump_criu_ns_ids(void) return predump_task_ns_ids(&crt.i); } +static int set_top_pid_ns(void) +{ + struct ns_id *ns; + + for (ns = ns_ids; ns != NULL; ns = ns->next) { + if (ns->nd != &pid_ns_desc) + continue; + if (ns->type == NS_ROOT) { + top_pid_ns = ns; + break; + } + if (ns->type == NS_CRIU) + top_pid_ns = ns; + } + + if (!top_pid_ns) { + pr_err("Can't set top_pid_ns\n"); + return -1; + } + + return 0; +} + static int collect_pstree_ids_predump() { struct pstree_item *item; @@ -834,7 +857,7 @@ static int collect_pstree_ids_predump() return -1; } - return 0; + return set_top_pid_ns(); } int collect_pstree_ids(void) @@ -845,7 +868,7 @@ int collect_pstree_ids(void) if (get_task_ids(item)) return -1; - return 0; + return set_top_pid_ns(); } static int collect_file_locks(void) diff --git a/criu/namespaces.c b/criu/namespaces.c index d41126215..5b0b3117a 100644 --- a/criu/namespaces.c +++ b/criu/namespaces.c @@ -448,11 +448,8 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd if (nd == &net_ns_desc) { INIT_LIST_HEAD(&nsid->net.ids); INIT_LIST_HEAD(&nsid->net.links); - } else if (nd == &pid_ns_desc) { + } else if (nd == &pid_ns_desc) nsid->pid.rb_root = RB_ROOT; - if (type == NS_ROOT || (type == NS_CRIU && !top_pid_ns)) - top_pid_ns = nsid; - } found: if (ns_ret) *ns_ret = nsid;