[CRIU] [PATCH 1/5] pipe: don't create a tranport descriptor for inhereted pipes

Pavel Emelyanov xemul at parallels.com
Tue Jul 14 04:10:29 PDT 2015


On 07/02/2015 12:47 PM, Andrey Vagin wrote:
> Otherwise we can get an error like this:
> 1: \t\tCreate transport fd /crtools-fd-1-5
> ...
> 1: Found id pipe:[122747] (fd 8) in inherit fd list
> 1: File pipe:[122747] will be restored from fd 9 duped from inherit
> 
> 1: Error (util.c:131): fd 5 already in use (called at files.c:872)
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  files.c |  3 +++
>  pipes.c | 20 ++++++++++++--------
>  2 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/files.c b/files.c
> index 4eeb988..3e69be7 100644
> --- a/files.c
> +++ b/files.c
> @@ -1394,6 +1394,9 @@ bool inherited_fd(struct file_desc *d, int *fd_p)
>  	if (i_fd < 0)
>  		return false;
>  
> +	if (fd_p == NULL)
> +		return true;
> +
>  	*fd_p = dup(i_fd);
>  	if (*fd_p < 0)
>  		pr_perror("Inherit fd DUP failed");
> diff --git a/pipes.c b/pipes.c
> index 7590472..62f550c 100644
> --- a/pipes.c
> +++ b/pipes.c
> @@ -393,18 +393,22 @@ static int collect_one_pipe(void *o, ProtobufCMessage *base)
>  	pr_info("Collected pipe entry ID %#x PIPE ID %#x\n",
>  			pi->pe->id, pi->pe->pipe_id);
>  
> -	list_for_each_entry(tmp, &pipes, list)
> -		if (pi->pe->pipe_id == tmp->pe->pipe_id)
> -			break;
> +	if (file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops))
> +		return -1;
>  
> -	if (&tmp->list == &pipes)
> -		INIT_LIST_HEAD(&pi->pipe_list);

This INIT_LIST_HEAD() is lost in + parts while shouldn't -- new pipes
MAY be added to it.

> -	else
> -		list_add(&pi->pipe_list, &tmp->pipe_list);
> +	INIT_LIST_HEAD(&pi->pipe_list);
> +	if (!inherited_fd(&pi->d, NULL)) {
> +		list_for_each_entry(tmp, &pipes, list)
> +			if (pi->pe->pipe_id == tmp->pe->pipe_id)
> +				break;
> +
> +		if (&tmp->list != &pipes)
> +			list_add(&pi->pipe_list, &tmp->pipe_list);
> +	}
>  
>  	list_add_tail(&pi->list, &pipes);
> -	return file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops);
>  
> +	return 0;
>  }
>  
>  struct collect_image_info pipe_cinfo = {
> 



More information about the CRIU mailing list