[CRIU] [PATCH 3/9] cr-restore: set cr_error to EEXIST if such pid already exists, v3
Ruslan Kuprieiev
kupruser at gmail.com
Thu Dec 11 12:55:12 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
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
cr-restore.c | 11 ++++++++++-
include/cr-errno.h | 1 +
include/rst_info.h | 1 +
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/cr-restore.c b/cr-restore.c
index 93a6ca6..afef81c 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;
@@ -855,6 +858,9 @@ static inline int sig_fatal(int sig)
struct task_entries *task_entries;
static unsigned long task_entries_pos;
+#define set_task_cr_err(new_err) atomic_cmpxchg(&task_entries->cr_err, 0, new_err)
+#define get_task_cr_err() atomic_read(&task_entries->cr_err)
+
static int restore_one_zombie(int pid, CoreEntry *core)
{
int exit_code = core->tc->exit_code;
@@ -1412,6 +1418,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 +1542,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 b8d27d2..d2f7071 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
*/
#endif /* __CR_ERRNO_H__ */
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 {
--
1.9.3
More information about the CRIU
mailing list