[CRIU] [PATCH 1/3] pstree: Simplify get_free_pid()

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jan 25 07:28:45 PST 2017


The expression rb_entry(node, struct pstree_item, pid.node)
may create a fake impression, that we dereferrence pstree_item
for threads too, which is a BUG, but it's not so, because
we are only interested in its ->pid field.

But anyway, escape of pstree_item, iterate over struct pid,
which are more readable.

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

diff --git a/criu/pstree.c b/criu/pstree.c
index 8eeea947c..b66116d7f 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -585,23 +585,23 @@ static int read_pstree_image(pid_t *pid_max)
 #define RESERVED_PIDS           300
 static int get_free_pid()
 {
-	static struct pstree_item *prev, *next;
+	static struct pid *prev, *next;
 
 	if (prev == NULL)
-		prev = rb_entry(rb_first(&pid_root_rb), struct pstree_item, pid.node);
+		prev = rb_entry(rb_first(&pid_root_rb), struct pid, node);
 
 	while (1) {
 		struct rb_node *node;
 		pid_t pid;
 
-		pid = prev->pid.virt + 1;
+		pid = prev->virt + 1;
 		pid = pid < RESERVED_PIDS ? RESERVED_PIDS + 1 : pid;
 
-		node = rb_next(&prev->pid.node);
+		node = rb_next(&prev->node);
 		if (node == NULL)
 			return pid;
-		next = rb_entry(node, struct pstree_item, pid.node);
-		if (next->pid.virt > pid)
+		next = rb_entry(node, struct pid, node);
+		if (next->virt > pid)
 			return pid;
 		prev = next;
 	}



More information about the CRIU mailing list