[CRIU] [PATCH] dump: Allocate root_item before run pre-dump scripts

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 8 06:38:40 PDT 2016


This allows pre-dump scripts to know CT root_item pid
and enter into its namespaces.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-dump.c       |   14 ++++++++++++--
 criu/include/seize.h |    2 +-
 criu/seize.c         |    9 ++-------
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 6648dd4..00d28e9 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -1471,6 +1471,11 @@ int cr_pre_dump_tasks(pid_t pid)
 	int ret = -1;
 	LIST_HEAD(ctls);
 
+	root_item = alloc_pstree_item();
+	if (!root_item)
+		goto err;
+	root_item->pid.real = pid;
+
 	if (!opts.track_mem) {
 		pr_info("Enforcing memory tracking for pre-dump.\n");
 		opts.track_mem = true;
@@ -1505,7 +1510,7 @@ int cr_pre_dump_tasks(pid_t pid)
 	if (setup_alarm_handler())
 		goto err;
 
-	if (collect_pstree(pid))
+	if (collect_pstree())
 		goto err;
 
 	if (collect_pstree_ids_predump())
@@ -1616,6 +1621,11 @@ int cr_dump_tasks(pid_t pid)
 	pr_info("Dumping processes (pid: %d)\n", pid);
 	pr_info("========================================\n");
 
+	root_item = alloc_pstree_item();
+	if (!root_item)
+		goto err;
+	root_item->pid.real = pid;
+
 	pre_dump_ret = run_scripts(ACT_PRE_DUMP);
 	if (pre_dump_ret != 0) {
 		pr_err("Pre dump script failed with %d!\n", pre_dump_ret);
@@ -1668,7 +1678,7 @@ int cr_dump_tasks(pid_t pid)
 	 * afterwards.
 	 */
 
-	if (collect_pstree(pid))
+	if (collect_pstree())
 		goto err;
 
 	if (collect_pstree_ids())
diff --git a/criu/include/seize.h b/criu/include/seize.h
index 9cfebb1..cf7366c 100644
--- a/criu/include/seize.h
+++ b/criu/include/seize.h
@@ -1,7 +1,7 @@
 #ifndef __CR_SEIZE_H__
 #define __CR_SEIZE_H__
 
-extern int collect_pstree(pid_t pid);
+extern int collect_pstree(void);
 extern void pstree_switch_state(struct pstree_item *root_item, int st);
 extern const char *get_real_freezer_state(void);
 extern bool alarm_timeouted(void);
diff --git a/criu/seize.c b/criu/seize.c
index 09eb65c..fb78a0b 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -650,8 +650,9 @@ static int collect_task(struct pstree_item *item)
 	return -1;
 }
 
-int collect_pstree(pid_t pid)
+int collect_pstree(void)
 {
+	pid_t pid = root_item->pid.real;
 	int ret = -1;
 
 	timing_start(TIME_FREEZING);
@@ -666,12 +667,6 @@ int collect_pstree(pid_t pid)
 	if (opts.freeze_cgroup && freeze_processes())
 		goto err;
 
-	root_item = alloc_pstree_item();
-	if (root_item == NULL)
-		goto err;
-
-	root_item->pid.real = pid;
-
 	if (!opts.freeze_cgroup && seize_catch_task(pid)) {
 		set_cr_errno(ESRCH);
 		goto err;



More information about the CRIU mailing list