[CRIU] [PATCH 05/11] pstree: add is_session_leader helper and use it where possible
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Fri May 26 10:02:48 PDT 2017
equal_pid(item->pid, item->sid) -> is_session_leader(item)
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
criu/cr-restore.c | 2 +-
criu/include/pstree.h | 1 +
criu/pstree.c | 19 ++++++++++++++-----
criu/tty.c | 4 ++--
4 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 238b05b..94e4f99 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1482,7 +1482,7 @@ static void restore_sid(void)
* we can call setpgid() on custom values.
*/
- if (equal_pid(current->pid, current->sid)) {
+ if (is_session_leader(current)) {
pr_info("Restoring %d to %d sid\n", vpid(current), vsid(current));
sid = setsid();
if (sid != last_level_pid(current->sid)) {
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index 85679d6..bbd29c1 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -88,6 +88,7 @@ static inline bool task_alive(struct pstree_item *i)
return is_alive_state(i->pid->state);
}
+extern int is_session_leader(struct pstree_item *item);
extern int get_free_pids(struct ns_id *ns, pid_t *pids);
extern void free_pstree_item(struct pstree_item *item);
extern void free_pstree(struct pstree_item *root_item);
diff --git a/criu/pstree.c b/criu/pstree.c
index 2f183f7..efff3d7 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -337,6 +337,15 @@ static int plant_ns_xid(uint32_t **ns_xid, size_t *n_ns_xid, int level, struct p
return 0;
}
+int is_session_leader(struct pstree_item *item)
+{
+ if (vsid(item) == vpid(item)) {
+ BUG_ON(!equal_pid(item->pid, item->sid));
+ return 1;
+ }
+ return 0;
+}
+
int dump_pstree(struct pstree_item *root_item)
{
struct pstree_item *item = root_item;
@@ -357,7 +366,7 @@ int dump_pstree(struct pstree_item *root_item)
* deeper in process tree, thus top-level checking for
* leader is enough.
*/
- if (!equal_pid(root_item->pid, root_item->sid)) {
+ if (!is_session_leader(root_item)) {
if (!opts.shell_job) {
pr_err("The root process %d is not a session leader. "
"Consider using --" OPT_SHELL_JOB " option\n", vpid(item));
@@ -423,7 +432,7 @@ static int prepare_pstree_for_shell_job(void)
if (!opts.shell_job)
return 0;
- if (equal_pid(root_item->sid, root_item->pid))
+ if (is_session_leader(root_item))
return 0;
/*
@@ -914,7 +923,7 @@ static int prepare_pstree_ids(void)
* a session leader himself -- this is a simple case, we
* just proceed in a normal way.
*/
- if (equal_pid(item->sid, root_item->sid) || equal_pid(item->sid, item->pid))
+ if (equal_pid(item->sid, root_item->sid) || is_session_leader(item))
continue;
leader = pstree_item_by_virt(vsid(item));
@@ -964,7 +973,7 @@ static int prepare_pstree_ids(void)
list_for_each_entry_safe_continue(child, tmp, &root_item->children, sibling) {
if (!equal_pid(child->sid, helper->sid))
continue;
- if (equal_pid(child->sid, child->pid))
+ if (is_session_leader(child))
continue;
pr_info("Attach %d to the temporary task %d\n",
@@ -983,7 +992,7 @@ static int prepare_pstree_ids(void)
if (item->pid->state == TASK_HELPER)
continue;
- if (!equal_pid(item->sid, item->pid)) {
+ if (!is_session_leader(item)) {
struct pstree_item *parent;
if (equal_pid(item->parent->sid, item->sid))
diff --git a/criu/tty.c b/criu/tty.c
index cf21cbd..0835934 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -1042,7 +1042,7 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
* checkpoint complete process tree together with
* the process which keeps the master peer.
*/
- if (!equal_pid(root_item->sid, root_item->pid)) {
+ if (!is_session_leader(root_item)) {
pr_debug("Restore inherited group %d\n",
getpgid(getppid()));
if (tty_set_prgp(fd, getpgid(getppid())))
@@ -1293,7 +1293,7 @@ static int tty_find_restoring_task(struct tty_info *info)
* for us.
*/
item = find_first_sid(info->tie->sid);
- if (item && equal_pid(item->pid, item->sid)) {
+ if (item && is_session_leader(item)) {
pr_info("Set a control terminal %#x to %d\n",
info->tfe->id, info->tie->sid);
return prepare_ctl_tty(vpid(item),
--
2.9.3
More information about the CRIU
mailing list