[RESEND,v1,22/55] pstree: Move parent assignment in read_pstree_image() up

Submitted by Kirill Tkhai on March 24, 2017, 3:12 p.m.

Details

Message ID 149036835633.23093.1150373835046434168.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai March 24, 2017, 3:12 p.m.
Move block with finding of parent item up in the function.
No functional changes, only changing the order.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/pstree.c |   29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/pstree.c b/criu/pstree.c
index 0e8a16f1..762c592b 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -529,10 +529,11 @@  static int read_pstree_ids(pid_t pid, TaskKobjIdsEntry **ids)
 
 static int read_pstree_image(pid_t *pid_max)
 {
+	struct pstree_item *pi, *parent;
 	TaskKobjIdsEntry *ids;
 	int ret = 0, i;
 	struct cr_img *img;
-	struct pstree_item *pi;
+	struct pid *pid;
 
 	pr_info("Reading image tree\n");
 
@@ -552,6 +553,18 @@  static int read_pstree_image(pid_t *pid_max)
 			break;
 
 		ret = -1;
+
+		parent = NULL;
+		if (e->ppid) {
+			pid = pstree_pid_by_virt(e->ppid);
+			if (!pid || pid->state == TASK_UNDEF || pid->state == TASK_THREAD) {
+				pr_err("Can't find a parent for %d\n", e->pid);
+				pstree_entry__free_unpacked(e, NULL);
+				break;
+			}
+			parent = pid->item;
+		}
+
 		pi = lookup_create_item(e->pid);
 		if (pi == NULL)
 			break;
@@ -581,7 +594,7 @@  static int read_pstree_image(pid_t *pid_max)
 			*pid_max = e->sid;
 		pi->pid->state = TASK_ALIVE;
 
-		if (e->ppid == 0) {
+		if (!parent) {
 			if (root_item) {
 				pr_err("Parent missed on non-root task "
 				       "with pid %d, image corruption!\n", e->pid);
@@ -590,18 +603,6 @@  static int read_pstree_image(pid_t *pid_max)
 			root_item = pi;
 			pi->parent = NULL;
 		} else {
-			struct pid *pid;
-			struct pstree_item *parent;
-
-			pid = pstree_pid_by_virt(e->ppid);
-			if (!pid || pid->state == TASK_UNDEF || pid->state == TASK_THREAD) {
-				pr_err("Can't find a parent for %d\n", vpid(pi));
-				pstree_entry__free_unpacked(e, NULL);
-				xfree(pi);
-				goto err;
-			}
-
-			parent = pid->item;
 			pi->parent = parent;
 			list_add(&pi->sibling, &parent->children);
 		}