[CRIU] [PATCH 03/9] cr-restore: set cr_error to EEXIST if such pid already, exists, v4

Ruslan Kuprieiev kupruser at gmail.com
Fri Dec 19 10:14:46 PST 2014


This is a very common error when using criu.

The problem here is that we need to somehow transfer cr_errno
from one process to another. I suggest using pipe to give
one end to children and read cr_errno on other after restore
is finished.

v2, Pavel suggested putting errno into shared task_entries.
v3. and he also suggested using cmpxchg
v4, introduce cr_err helpers in a separate patch

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 cr-restore.c       | 8 +++++++-
 include/cr-errno.h | 1 +
 include/rst_info.h | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/cr-restore.c b/cr-restore.c
index 93a6ca6..52670fa 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -84,6 +84,9 @@
 #include "protobuf/siginfo.pb-c.h"
 
 #include "asm/restore.h"
+#include "asm/atomic.h"
+
+#include "cr-errno.h"
 
 static struct pstree_item *current;
 
@@ -1412,6 +1415,7 @@ static int restore_task_with_children(void *_arg)
 	pid = getpid();
 	if (current->pid.virt != pid) {
 		pr_err("Pid %d do not match expected %d\n", pid, current->pid.virt);
+		set_task_cr_err(EEXIST);
 		goto err;
 	}
 
@@ -1535,8 +1539,10 @@ static int restore_wait_inprogress_tasks()
 
 	futex_wait_while_gt(np, 0);
 	ret = (int)futex_get(np);
-	if (ret < 0)
+	if (ret < 0) {
+		set_cr_errno(get_task_cr_err());
 		return ret;
+	}
 
 	return 0;
 }
diff --git a/include/cr-errno.h b/include/cr-errno.h
index 31ddccb..1fd94a0 100644
--- a/include/cr-errno.h
+++ b/include/cr-errno.h
@@ -7,6 +7,7 @@ int get_cr_errno(void);
 /*
  * List of symbolic error names:
  * ESRCH	- no process can be found corresponding to that specified by pid
+ * EEXIST	- process with such pid already exists
  */
 
 #define set_task_cr_err(new_err)	atomic_cmpxchg(&task_entries->cr_err, 0, new_err)
diff --git a/include/rst_info.h b/include/rst_info.h
index 6b00c50..d509c0c 100644
--- a/include/rst_info.h
+++ b/include/rst_info.h
@@ -10,6 +10,7 @@ struct task_entries {
 	futex_t nr_in_progress;
 	futex_t start;
 	mutex_t	zombie_lock;
+	atomic_t cr_err;
 };
 
 struct fdt {
-- 
2.1.0



More information about the CRIU mailing list