[CRIU] [PATCHv3 7/8] remote: Use tmp file buffer when restore ip dump

Andrei Vagin avagin at virtuozzo.com
Mon Sep 10 22:11:13 MSK 2018


On Tue, Sep 04, 2018 at 10:26:56PM +0100, Radostin Stoyanov wrote:
> When CRIU calls the ip tool on restore, it passes the fd of remote
> socket by replacing the STDIN before execvp. The stdin is used by the
> ip tool to receive input. However, the ip tool calls ftell(stdin)
> which fails with "Illegal seek" since UNIX sockets do not support file
> positioning operations. To resolve this issue, read the received
> content from the UNIX socket and store it into temporary file, then
> replace STDIN with the fd of this tmp file.
> 
> Fixes #311
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
> ---
>  criu/net.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/net.c b/criu/net.c
> index 0431b62f..679212d0 100644
> --- a/criu/net.c
> +++ b/criu/net.c
> @@ -1914,19 +1914,27 @@ out:
>  
>  static int restore_ip_dump(int type, int pid, char *cmd)
>  {
> -	int ret = -1;
> +	int ret = -1, sockfd, n;
> +	FILE *tmp_file;
>  	struct cr_img *img;
> +	char buf[1024];
>  
>  	img = open_image(type, O_RSTR, pid);
>  	if (empty_image(img)) {
>  		close_image(img);
>  		return 0;
>  	}
> +	sockfd = img_raw_fd(img);
> +	tmp_file = tmpfile();
> +	while ((n = read(sockfd, buf, 1024)) > 0)
> +		fwrite(buf, sizeof(char), n, tmp_file);

I think we have to check errors of all fxxxx calls

> +	fseek(tmp_file, 0, SEEK_SET);
> +
>  	if (img) {
> -		ret = run_ip_tool(cmd, "restore", NULL, NULL, img_raw_fd(img), -1, 0);
> +		ret = run_ip_tool(cmd, "restore", NULL, NULL, fileno(tmp_file), -1, 0);
>  		close_image(img);
>  	}
> -
> +	fclose(tmp_file);
>  	return ret;
>  }
>  
> -- 
> 2.17.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list