[05/14] restore: Always set real pid in restore_task_with_children()

Submitted by Kirill Tkhai on May 15, 2017, 1:05 p.m.

Details

Message ID 149485351721.681.16470098635264374472.stgit@localhost.localdomain
State New
Series "Refactor pid_ns helpers creation"
Headers show

Commit Message

Kirill Tkhai May 15, 2017, 1:05 p.m.
In next patches, root_item will need to have its real pid
to be sure, usernsd already sees it.

Also add a comment, explaning why set real pid in two places.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/cr-restore.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index ccee39ebf..f516ab0d4 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1265,8 +1265,8 @@  static int do_fork_with_pid(struct pstree_item *item, struct ns_id *pid_ns, stru
 			close_pid_proc();
 		pid = clone_noasan(restore_task_with_children, ca->clone_flags | SIGCHLD, ca);
 		if (item == root_item) {
+			/* We want to use it before it's set in restore_task_with_children() */
 			item->pid->real = pid;
-			pr_debug("PID: real %d virt %d\n", pid, vpid(item));
 		}
 		return pid > 0 ? 0 : -1;
 	}
@@ -1689,13 +1689,10 @@  static int restore_task_with_children(void *_arg)
 
 	current = ca->item;
 
-	if (current != root_item) {
-		current->pid->real = get_self_real_pid();
-		pr_debug("PID: real %d virt %d\n",
-				current->pid->real, vpid(current));
-		if (current->pid->real < 0)
-			goto err;
-	}
+	current->pid->real = get_self_real_pid();
+	pr_debug("PID: real %d virt %d\n", current->pid->real, vpid(current));
+	if (current->pid->real < 0)
+		goto err;
 
 	if ( !(ca->clone_flags & CLONE_FILES))
 		close_safe(&ca->fd);