[CRIU] Re: [PATCH 06/14] pstree: Allow to dump and restore session
non-leaders if --shell-job passed
Pavel Emelyanov
xemul at parallels.com
Mon Oct 15 12:00:11 EDT 2012
On 10/15/2012 06:54 PM, Cyrill Gorcunov wrote:
>
> If --shell-job passed we allow to dump and restpre session non-leaders.
>
> This slightly changes the behaviour or the tool. If previously
> we allowed to dump non-leaders after this commit we refuse to
> do that if not explicitly requested.
>
> Note that in sake of tty restore (which will be addressed in
> further patches) we do inherit process group for root task.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> include/pstree.h | 8 +++++
> pstree.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 98 insertions(+), 2 deletions(-)
>
> @@ -61,4 +68,5 @@ extern int dump_pstree(struct pstree_item *root_item);
>
> struct task_entries;
> extern struct task_entries *task_entries;
> +
> #endif
Trash
> + if (root_item->pid.virt != root_item->sid) {
> + if (!opts.shell_job) {
> + pr_err("The root process %d is not a session leader, "
> + "miss to specify %s option?\n",
> + item->pid.virt, "--shell-job");
%s for hard-coded string is strange. Declare a macro for it and use it here and
in the --help message.
> + return -1;
> + }
> +
> + * PID GID SID
> + * 4 3 2 root-task
> + * 5 3 2 `- task-1
> + * 6 6 2 `- task-2
> + *
> + * So when we migrate a shell job we need the task-1 to inherit
> + * GID from root task, thus we put INHERIT_PGID in the image.
> + */
> + if (item->pgid == origin_sid)
> + e.pgid = INHERIT_SID;
His case is not described in the comment above.
> + else if (item->pgid == origin_pgid)
> + e.pgid = INHERIT_PGID;
> + else
> + e.pgid = item->pgid;
> @@ -102,6 +158,16 @@ int dump_pstree(struct pstree_item *root_item)
> ret = 0;
>
> err:
> +
> + /*
> + * Don't forget to restore changed values, we keep
> + * process tree solid in memory.
Where did we change them?
> + */
> + if (origin_sid != INHERIT_SID) {
> + root_item->sid = origin_sid;
> + root_item->pgid = origin_pgid;
> + }
> +
> pr_info("----------------------------------------\n");
> close(pstree_fd);
> return ret;
> struct pstree_item *root_item;
>
> +static pid_t current_sid = INHERIT_SID;
> +static pid_t current_pgid = INHERIT_PGID;
> +
These two are not used outside of the prepare_pstree() and _ids() and the
latter can be directly called from the former. Thus no need in two more
global variables.
More information about the CRIU
mailing list