[CRIU] [PATCH 1/2] scripts: Do not set -1 as root item pid

Andrew Vagin avagin at virtuozzo.com
Thu Apr 28 13:33:34 PDT 2016


Acked-by: Andrew Vagin <avagin at virtuozzo.com>

On Thu, Apr 28, 2016 at 05:46:26PM +0300, Pavel Emelyanov wrote:
> On restore root_item may exist, but its real pid is not yet resolved
> Fixes e5e8f791.
> 
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
> ---
>  criu/action-scripts.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/criu/action-scripts.c b/criu/action-scripts.c
> index aa64703..ee59210 100644
> --- a/criu/action-scripts.c
> +++ b/criu/action-scripts.c
> @@ -44,7 +44,6 @@ static int run_shell_scripts(const char *action)
>  	int ret = 0;
>  	struct script *script;
>  	char image_dir[PATH_MAX];
> -	char root_item_pid[16];
>  	static unsigned env_set = 0;
>  
>  #define ENV_IMGDIR	0x1
> @@ -65,12 +64,18 @@ static int run_shell_scripts(const char *action)
>  	}
>  
>  	if (!(env_set & ENV_ROOTPID) && root_item) {
> -		snprintf(root_item_pid, sizeof(root_item_pid), "%d", root_item->pid.real);
> -		if (setenv("CRTOOLS_INIT_PID", root_item_pid, 1)) {
> -			pr_perror("Can't set CRTOOLS_INIT_PID=%s", root_item_pid);
> -			return -1;
> +		int pid;
> +		char root_item_pid[16];
> +
> +		pid = root_item->pid.real;
> +		if (pid != -1) {
> +			snprintf(root_item_pid, sizeof(root_item_pid), "%d", pid);
> +			if (setenv("CRTOOLS_INIT_PID", root_item_pid, 1)) {
> +				pr_perror("Can't set CRTOOLS_INIT_PID=%s", root_item_pid);
> +				return -1;
> +			}
> +			env_set |= ENV_ROOTPID;
>  		}
> -		env_set |= ENV_ROOTPID;
>  	}
>  
>  	list_for_each_entry(script, &scripts, node) {
> -- 
> 2.5.0
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list