[CRIU] [PATCH v2 3/3] cr-restore: set NS_PID environment variable before "post-resume" hook

Pavel Emelyanov xemul at virtuozzo.com
Tue Apr 12 02:07:43 PDT 2016


On 04/06/2016 01:09 PM, Stanislav Kinsburskiy wrote:
> The only one (so far) "post-resume" script needs some pid to join its
> namespaces. Let it be containers root.
> 
> Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
> ---
>  criu/cr-restore.c |    8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/criu/cr-restore.c b/criu/cr-restore.c
> index 2b11b71..834d606 100644
> --- a/criu/cr-restore.c
> +++ b/criu/cr-restore.c
> @@ -1995,6 +1995,7 @@ static int restore_root_task(struct pstree_item *init)
>  	enum trace_flags flag = TRACE_ALL;
>  	int ret, fd, mnt_ns_fd = -1;
>  	int clean_remaps = 1;
> +	char root_item_pid[16];
>  
>  	ret = run_scripts(ACT_PRE_RESTORE);
>  	if (ret != 0) {
> @@ -2198,6 +2199,13 @@ static int restore_root_task(struct pstree_item *init)
>  	if (!opts.restore_detach && !opts.exec_cmd)
>  		wait(NULL);
>  
> +	snprintf(root_item_pid, sizeof(root_item_pid), "%d", root_item->pid.real);
> +
> +	if (setenv("NS_PID", root_item_pid, 1)) {

Let's make it consistent with the rest of scripts' environment and
a) setup environment in run_scripts()
b) name it CRTOOLS_$SOMETHING as the other variables are

> +		pr_perror("Can't set NS_PID=%s", root_item_pid);
> +		return -1;
> +	}
> +
>  	ret = run_scripts(ACT_POST_RESUME);
>  	if (ret != 0)
>  		pr_err("Post-resume script ret code %d\n", ret);
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
> .
> 



More information about the CRIU mailing list