[CRIU] [PATCHv4 1/3] pstree: Add nspid() helper

Dmitry Safonov dsafonov at virtuozzo.com
Thu Jul 20 18:21:20 MSK 2017


To get pid in ns of current.

Reviewed-by: Kirill Tkhai <ktkhai at virtuozzo.com>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 criu/cr-restore.c     | 6 ++----
 criu/include/pstree.h | 6 ++++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index e14fa0694a98..9143cd310fed 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -769,7 +769,6 @@ static int prepare_sigactions(CoreEntry *core)
 
 static int __collect_child_pids(struct pstree_item *p, int state, unsigned int *n)
 {
-	int level = current->pid->level;
 	struct pstree_item *pi;
 
 	list_for_each_entry(pi, &p->children, sibling) {
@@ -783,7 +782,7 @@ static int __collect_child_pids(struct pstree_item *p, int state, unsigned int *
 			return -1;
 
 		(*n)++;
-		*child = pi->pid->ns[level-1].virt;
+		*child = nspid(pi);
 	}
 
 	return 0;
@@ -1083,11 +1082,10 @@ static unsigned long task_entries_pos;
 
 static int wait_on_helpers_zombies(void)
 {
-	int level = current->pid->level;
 	struct pstree_item *pi;
 
 	list_for_each_entry(pi, &current->children, sibling) {
-		pid_t pid = pi->pid->ns[level-1].virt;
+		pid_t pid = nspid(pi);
 		int status;
 
 		switch (pi->pid->state) {
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index a3d8c3123852..08f25384f2c5 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -33,6 +33,10 @@ struct pstree_item {
 	struct ns_id		*pid_for_children_ns;
 };
 
+extern struct pstree_item *current;
+
+#define nspid(item)	(item->pid->ns[current->pid->level - 1].virt)
+
 #define vpid(item)	(item->pid->ns[0].virt)
 #define vsid(item)	(item->sid->ns[0].virt)
 #define vpgid(item)	(item->pgid->ns[0].virt)
@@ -45,8 +49,6 @@ enum {
 };
 #define FDS_EVENT (1 << FDS_EVENT_BIT)
 
-extern struct pstree_item *current;
-
 struct rst_info;
 /* See alloc_pstree_item() for details */
 static inline struct rst_info *rsti(struct pstree_item *i)
-- 
2.13.3



More information about the CRIU mailing list