[02/14] restore: Simplify do_fork_with_pid()

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

Details

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

Commit Message

Kirill Tkhai May 15, 2017, 1:04 p.m.
memcpy() is not need here, as we rewrite all the fields later.
Also, use PID_SIZE() helper.

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

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 259964d74..966a759b6 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1257,7 +1257,7 @@  static int call_clone_fn(void *arg)
 
 static int do_fork_with_pid(struct pstree_item *item, struct ns_id *pid_ns, struct cr_clone_arg *ca)
 {
-	int status, i, sz, ret = 0;
+	int status, i, ret = 0;
 	struct pid *hlp_pid;
 	sigset_t sig_mask;
 	pid_t pid;
@@ -1277,12 +1277,10 @@  static int do_fork_with_pid(struct pstree_item *item, struct ns_id *pid_ns, stru
 		return pid > 0 ? 0 : -1;
 	}
 
-	sz = sizeof(struct pid) + (item->pid->level - 2) * sizeof(((struct pid *)NULL)->ns[0]);
-	hlp_pid = xmalloc(sz);
+	hlp_pid = xmalloc(PID_SIZE(item->pid->level-1));
 	if (!hlp_pid)
 		return -1;
-	memcpy(hlp_pid, item->pid, sz);
-	hlp_pid->level--;
+	hlp_pid->level = item->pid->level - 1;
 
 	for (i = 0; i < hlp_pid->level; i++) {
 		/*
@@ -1290,7 +1288,7 @@  static int do_fork_with_pid(struct pstree_item *item, struct ns_id *pid_ns, stru
 		 * This should guarantee the helper will not
 		 * occupy child's pids.
 		 */
-		hlp_pid->ns[i].virt++;
+		hlp_pid->ns[i].virt = item->pid->ns[i].virt + 1;
 		if (hlp_pid->ns[i].virt < 0)
 			hlp_pid->ns[i].virt = INIT_PID + 1;
 	}