[CRIU] [PATCH 1/3] cr-service: open FDs passed via inherit_fd option also in RPC mode

Andrei Vagin avagin at virtuozzo.com
Wed Jul 25 03:30:32 MSK 2018


On Mon, Jul 23, 2018 at 07:13:31PM +0000, Adrian Reber wrote:
> From: Adrian Reber <areber at redhat.com>
> 
> Signed-off-by: Adrian Reber <areber at redhat.com>
> ---
>  criu/cr-service.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/cr-service.c b/criu/cr-service.c
> index 3a07d5b76..14fb45635 100644
> --- a/criu/cr-service.c
> +++ b/criu/cr-service.c
> @@ -242,6 +242,8 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  	char images_dir_path[PATH_MAX];
>  	char work_dir_path[PATH_MAX];
>  	char status_fd[PATH_MAX];
> +	char inherit_fd[PATH_MAX];
> +	int fd;
>  	int i;
>  
>  	if (getsockopt(sk, SOL_SOCKET, SO_PEERCRED, &ids, &ids_len)) {
> @@ -415,7 +417,11 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  		goto err;
>  	}
>  	for (i = 0; i < req->n_inherit_fd; i++) {
> -		if (inherit_fd_add(req->inherit_fd[i]->fd, req->inherit_fd[i]->key))
> +		sprintf(inherit_fd, "/proc/%d/fd/%d", ids.pid, req->inherit_fd[i]->fd);
> +		fd = open(inherit_fd, O_RDWR);

This will not work for sockets, read-only or write-only files, etc.

In case of rpc, inherited file descriptors have to be sent via a service
socket.

> +		if (fd < 0)
> +			goto err;
> +		if (inherit_fd_add(fd, req->inherit_fd[i]->key))
>  			goto err;
>  	}
>  
> -- 
> 2.18.0
> 


More information about the CRIU mailing list