[CRIU] Re: [PATCH 06/16] dump: use open instead of openat

Pavel Emelyanov xemul at parallels.com
Fri Mar 2 01:50:19 EST 2012


On 03/01/2012 09:56 PM, Kinsbursky Stanislav wrote:
> 
> 
> Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

NAK. openat is required not only for the reasons Cyrill pointed out, but
also when we will start dumping containers and will have to find its
proc in paths other than /proc.

> ---
>  cr-dump.c |   19 ++++++++++---------
>  1 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/cr-dump.c b/cr-dump.c
> index 9c1bf36..5af391c 100644
> --- a/cr-dump.c
> +++ b/cr-dump.c
> @@ -313,29 +313,31 @@ static int read_fd_params(pid_t pid, char *fd, struct fd_parms *p)
>  	return 0;
>  }
>  
> -static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset *cr_fdset,
> +static int dump_one_fd(pid_t pid, char *d_name, struct cr_fdset *cr_fdset,
>  		       struct sk_queue *sk_queue)
>  {
>  	struct stat fd_stat;
>  	int err = -1;
>  	struct fd_parms p;
>  	int lfd;
> +	char file_path[128];
>  
> +	snprintf(file_path, sizeof(file_path), "/proc/%d/fd/%s", pid, d_name);
>  	if (read_fd_params(pid, d_name, &p))
>  		return -1;
>  
> -	lfd = openat(pid_fd_dir, d_name, O_RDONLY);
> +	lfd = open(file_path, O_RDONLY);
>  	if (lfd < 0) {
>  		err = try_dump_socket(pid, p.fd_name, cr_fdset, sk_queue);
>  		if (err != 1)
>  			return err;
>  
> -		pr_perror("Failed to open %d/%ld", pid_fd_dir, p.fd_name);
> +		pr_perror("Failed to open '%s'", file_path);
>  		return -1;
>  	}
>  
> -	if (fstat(lfd, &fd_stat) < 0) {
> -		pr_perror("Can't get stat on %ld", p.fd_name);
> +	if (stat(file_path, &fd_stat)) {
> +		pr_perror("Can't stat %s", file_path);
>  		goto out_close;
>  	}
>  
> @@ -345,8 +347,8 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset
>  		/* skip only standard destriptors */
>  		if (p.fd_name < 3) {
>  			err = 0;
> -			pr_info("... Skipping tty ... %d/%ld\n",
> -				pid_fd_dir, p.fd_name);
> +			pr_info("... Skipping tty ... '%s'\n",
> +				file_path);
>  			goto out_close;
>  		}
>  		goto err;
> @@ -404,8 +406,7 @@ static int dump_task_files(pid_t pid, struct cr_fdset *cr_fdset,
>  			continue;
>  		if (!strcmp(de->d_name, ".."))
>  			continue;
> -		if (dump_one_fd(pid, dirfd(fd_dir), de->d_name, cr_fdset,
> -				sk_queue))
> +		if (dump_one_fd(pid, de->d_name, cr_fdset, sk_queue))
>  			return -1;
>  	}
>  
> 



More information about the CRIU mailing list