[CRIU] [PATCH 1/2] pstree: Make restore_finish_stage helper to use holder variable

Cyrill Gorcunov gorcunov at openvz.org
Wed Aug 24 03:32:27 PDT 2016


The @task_entries variable is declared as external in
criu/include/pstree.h and restore_finish_stage refers
to it implicitly. This is a bad habbit because the name
get propagated into pie code where we have a local
static variable, which eventually may shadow the former
copy with gcc 4.9 series as been reported by Nikolay.

Lets make restore_finish_stage helper to take variable
name explicitly.

Reported-by: Nikolay Borisov <kernel at kyup.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/cr-restore.c       | 10 +++++-----
 criu/include/restorer.h |  8 ++++----
 criu/pie/restorer.c     | 12 ++++++------
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 6ad82535d507..5daf04c8145e 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -816,7 +816,7 @@ static int restore_one_zombie(CoreEntry *core)
 	prctl(PR_SET_NAME, (long)(void *)core->tc->comm, 0, 0, 0);
 
 	if (task_entries != NULL) {
-		restore_finish_stage(CR_STATE_RESTORE);
+		restore_finish_stage(task_entries, CR_STATE_RESTORE);
 		zombie_prepare_signals();
 	}
 
@@ -898,7 +898,7 @@ static int restore_one_task(int pid, CoreEntry *core)
 			return -1;
 		}
 
-		restore_finish_stage(CR_STATE_RESTORE);
+		restore_finish_stage(task_entries, CR_STATE_RESTORE);
 		if (wait_on_helpers_zombies()) {
 			pr_err("failed to wait on helpers and zombies\n");
 			ret = -1;
@@ -1390,7 +1390,7 @@ static int restore_task_with_children(void *_arg)
 
 	/* Wait prepare_userns */
 	if (current->parent == NULL &&
-            restore_finish_stage(CR_STATE_RESTORE_NS) < 0)
+            restore_finish_stage(task_entries, CR_STATE_RESTORE_NS) < 0)
 			goto err;
 
 	/*
@@ -1426,7 +1426,7 @@ static int restore_task_with_children(void *_arg)
 		if (root_prepare_shared())
 			goto err;
 
-		if (restore_finish_stage(CR_STATE_RESTORE_SHARED) < 0)
+		if (restore_finish_stage(task_entries, CR_STATE_RESTORE_SHARED) < 0)
 			goto err;
 	}
 
@@ -1463,7 +1463,7 @@ static int restore_task_with_children(void *_arg)
 		fini_restore_mntns();
 	}
 
-	if (restore_finish_stage(CR_STATE_FORKING) < 0)
+	if (restore_finish_stage(task_entries, CR_STATE_FORKING) < 0)
 		goto err;
 
 	if (restore_one_task(current->pid.virt, ca->core))
diff --git a/criu/include/restorer.h b/criu/include/restorer.h
index 7c0336e7bf74..c74d25fdd908 100644
--- a/criu/include/restorer.h
+++ b/criu/include/restorer.h
@@ -214,10 +214,10 @@ enum {
 	CR_STATE_COMPLETE
 };
 
-#define restore_finish_stage(__stage) ({				\
-		futex_dec_and_wake(&task_entries->nr_in_progress);	\
-		futex_wait_while(&task_entries->start, __stage);	\
-		(s32) futex_get(&task_entries->start);			\
+#define restore_finish_stage(__v, __stage) ({			\
+		futex_dec_and_wake(&(__v)->nr_in_progress);	\
+		futex_wait_while(&(__v)->start, __stage);	\
+		(s32) futex_get(&(__v)->start);			\
 	})
 
 
diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c
index 7cc735c96870..f1d380bd6313 100644
--- a/criu/pie/restorer.c
+++ b/criu/pie/restorer.c
@@ -471,18 +471,18 @@ long __export_restore_thread(struct thread_restore_args *args)
 
 	pr_info("%ld: Restored\n", sys_gettid());
 
-	restore_finish_stage(CR_STATE_RESTORE);
+	restore_finish_stage(task_entries, CR_STATE_RESTORE);
 
 	if (restore_signals(args->siginfo, args->siginfo_n, false))
 		goto core_restore_end;
 
-	restore_finish_stage(CR_STATE_RESTORE_SIGCHLD);
+	restore_finish_stage(task_entries, CR_STATE_RESTORE_SIGCHLD);
 	restore_pdeath_sig(args);
 
 	if (args->ta->seccomp_mode != SECCOMP_MODE_DISABLED)
 		pr_info("Restoring seccomp mode %d for %ld\n", args->ta->seccomp_mode, sys_getpid());
 
-	restore_finish_stage(CR_STATE_RESTORE_CREDS);
+	restore_finish_stage(task_entries, CR_STATE_RESTORE_CREDS);
 
 	futex_dec_and_wake(&thread_inprogress);
 
@@ -1454,7 +1454,7 @@ long __export_restore_task(struct task_restore_args *args)
 
 	pr_info("%ld: Restored\n", sys_getpid());
 
-	restore_finish_stage(CR_STATE_RESTORE);
+	restore_finish_stage(task_entries, CR_STATE_RESTORE);
 
 	if (wait_helpers(args) < 0)
 		goto core_restore_end;
@@ -1491,7 +1491,7 @@ long __export_restore_task(struct task_restore_args *args)
 	if (ret)
 		goto core_restore_end;
 
-	restore_finish_stage(CR_STATE_RESTORE_SIGCHLD);
+	restore_finish_stage(task_entries, CR_STATE_RESTORE_SIGCHLD);
 
 	rst_tcp_socks_all(args);
 
@@ -1513,7 +1513,7 @@ long __export_restore_task(struct task_restore_args *args)
 
 	futex_set_and_wake(&thread_inprogress, args->nr_threads);
 
-	restore_finish_stage(CR_STATE_RESTORE_CREDS);
+	restore_finish_stage(task_entries, CR_STATE_RESTORE_CREDS);
 
 	if (ret)
 		BUG();
-- 
2.7.4



More information about the CRIU mailing list