[CRIU] [PATCH v2 05/10] pstree: add curr_sid/pgid updating them on fork/setsid/setpgid
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Tue Jul 4 14:33:52 MSK 2017
v2: move code in fork_with_pid to separate helper fork_update_curr
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
criu/cr-restore.c | 41 +++++++++++++++++++++++++++++++++++++++++
criu/include/rst_info.h | 3 +++
2 files changed, 44 insertions(+)
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 3ce27fd..7b4528b 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1379,6 +1379,39 @@ static int do_fork_with_pid(struct pstree_item *item, struct ns_id *pid_ns, stru
return ret;
}
+static inline int fork_update_curr(struct pstree_item *item)
+{
+ if (!item->parent) {
+ pid_t real_sid, real_pgid;
+
+ real_sid = getsid(0);
+ if (real_sid == -1) {
+ pr_perror("%d: Fail to getsid\n", vpid(item));
+ return -1;
+ }
+
+ real_pgid = getpgid(0);
+ if (real_pgid == -1) {
+ pr_perror("%d: Fail to getpgid\n", vpid(item));
+ return -1;
+ }
+
+ rsti(item)->curr_sid = real_sid;
+ rsti(item)->curr_pgid = real_pgid;
+ } else {
+ rsti(item)->curr_sid = rsti(item->parent)->curr_sid;
+ rsti(item)->curr_pgid = rsti(item->parent)->curr_pgid;
+ }
+
+ /* Check we are born with the right sid */
+ if (item->born_sid != -1)
+ BUG_ON(item->born_sid != rsti(item)->curr_sid);
+ else if (!is_session_leader(item))
+ BUG_ON(vsid(item) != rsti(item)->curr_sid);
+
+ return 0;
+}
+
static inline int fork_with_pid(struct pstree_item *item)
{
struct cr_clone_arg ca;
@@ -1386,6 +1419,9 @@ static inline int fork_with_pid(struct pstree_item *item)
pid_t pid = vpid(item);
struct ns_id *pid_ns;
+ if (fork_update_curr(item) == -1)
+ return -1;
+
if (item->pid->state != TASK_HELPER) {
if (open_core(pid, &ca.core))
return -1;
@@ -1541,6 +1577,8 @@ static void restore_sid(void)
pr_perror("Can't restore sid (%d)", sid);
exit(1);
}
+ rsti(current)->curr_sid = vpid(current);
+ rsti(current)->curr_pgid = vpid(current);
} else {
sid = getsid(getpid());
if (sid != last_level_pid(current->sid)) {
@@ -1552,6 +1590,8 @@ static void restore_sid(void)
exit(1);
}
}
+
+ BUG_ON(rsti(current)->curr_sid != vsid(current));
}
static void restore_pgid(void)
@@ -1598,6 +1638,7 @@ static void restore_pgid(void)
pr_perror("Can't restore pgid (%d/%d->%d)", vpid(current), pgid, vpgid(current));
exit(1);
}
+ rsti(current)->curr_pgid = vpid(current);
if (my_pgid == last_level_pid(current->pid))
futex_set_and_wake(&rsti(current)->pgrp_set, 1);
diff --git a/criu/include/rst_info.h b/criu/include/rst_info.h
index f9840d1..c1f8fdf 100644
--- a/criu/include/rst_info.h
+++ b/criu/include/rst_info.h
@@ -65,6 +65,9 @@ struct rst_info {
bool has_thp_enabled;
void *breakpoint;
+
+ int curr_sid;
+ int curr_pgid;
};
extern struct task_entries *task_entries;
--
2.9.4
More information about the CRIU
mailing list