Commit 9c9f9327 authored by Radostin Stoyanov's avatar Radostin Stoyanov Committed by Andrei Vagin

pstree: Restore task group leader when inherit SID

The current behaviour of CRIU is to inherit the group leader of the
parent process when migrating a session leader (with --shell-job).
However, it is possible for a process to be group leader without being
a session leader (e.g. a shell process). In this case CRIU should
restore the original group ID of the process and inherit only the
session ID.

Closes #593
Signed-off-by: 's avatarRadostin Stoyanov <rstoyanov1@gmail.com>
Reviewed-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@gmail.com>
parent 1be8269c
...@@ -367,22 +367,31 @@ static int prepare_pstree_for_shell_job(pid_t pid) ...@@ -367,22 +367,31 @@ static int prepare_pstree_for_shell_job(pid_t pid)
*/ */
old_sid = root_item->sid; old_sid = root_item->sid;
old_gid = root_item->pgid;
pr_info("Migrating process tree (GID %d->%d SID %d->%d)\n", pr_info("Migrating process tree (SID %d->%d)\n",
old_gid, current_gid, old_sid, current_sid); old_sid, current_sid);
for_each_pstree_item(pi) { for_each_pstree_item(pi) {
if (pi->pgid == old_gid)
pi->pgid = current_gid;
if (pi->sid == old_sid) if (pi->sid == old_sid)
pi->sid = current_sid; pi->sid = current_sid;
} }
old_gid = root_item->pgid;
if (old_gid != vpid(root_item)) {
if (lookup_create_item(current_sid) == NULL) if (lookup_create_item(current_sid) == NULL)
return -1; return -1;
pr_info("Migrating process tree (GID %d->%d)\n",
old_gid, current_gid);
for_each_pstree_item(pi) {
if (pi->pgid == old_gid)
pi->pgid = current_gid;
}
if (lookup_create_item(current_gid) == NULL) if (lookup_create_item(current_gid) == NULL)
return -1; return -1;
}
return 0; return 0;
} }
......
...@@ -1068,12 +1068,17 @@ out: ...@@ -1068,12 +1068,17 @@ out:
* the process which keeps the master peer. * the process which keeps the master peer.
*/ */
if (root_item->sid != vpid(root_item)) { if (root_item->sid != vpid(root_item)) {
if (root_item->pgid == vpid(root_item)) {
if (tty_set_prgp(fd, root_item->pgid))
goto err;
} else {
pr_debug("Restore inherited group %d\n", pr_debug("Restore inherited group %d\n",
getpgid(getppid())); getpgid(getppid()));
if (tty_set_prgp(fd, getpgid(getppid()))) if (tty_set_prgp(fd, getpgid(getppid())))
goto err; goto err;
} }
} }
}
if (pty_open_slaves(slave)) if (pty_open_slaves(slave))
goto err; goto err;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment