[CRIU] [PATCH 05/15] img: Use errno when checking optional images open fail

Andrew Vagin avagin at parallels.com
Mon Sep 29 03:12:24 PDT 2014


On Mon, Sep 29, 2014 at 12:47:54PM +0400, Pavel Emelyanov wrote:
> There will be no int-fd soon, so one more preparation
> to this fact.
> 
> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
> ---
>  cr-restore.c | 4 ++--
>  file-lock.c  | 2 +-
>  files.c      | 4 ++--
>  irmap.c      | 2 +-
>  mem.c        | 2 +-
>  protobuf.c   | 2 +-
>  6 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/cr-restore.c b/cr-restore.c
> index 9277433..ae083e8 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -2354,7 +2354,7 @@ static int prepare_rlimits_from_fd(int pid)
>  	 */
>  	fd = open_image(CR_FD_RLIMIT, O_RSTR | O_OPT, pid);
>  	if (fd < 0) {
> -		if (fd == -ENOENT) {
> +		if (errno == ENOENT) {

I don't like this. errno can be rewritten by any glibc call.

>  			pr_info("Skip rlimits for %d\n", pid);
>  			return 0;
>  		}
> @@ -2445,7 +2445,7 @@ static int open_signal_image(int type, pid_t pid, unsigned int *nr)
>  
>  	fd = open_image(type, O_RSTR | O_OPT, pid);
>  	if (fd < 0) {
> -		if (fd == -ENOENT) /* backward compatibility */
> +		if (errno == ENOENT) /* backward compatibility */
>  			return 0;
>  		else
>  			return -1;
> diff --git a/file-lock.c b/file-lock.c
> index 5fff77b..f97beae 100644
> --- a/file-lock.c
> +++ b/file-lock.c
> @@ -343,7 +343,7 @@ static int restore_file_locks_legacy(int pid)
>  
>  	fd = open_image(CR_FD_FILE_LOCKS_PID, O_RSTR | O_OPT, pid);
>  	if (fd < 0) {
> -		if (fd == -ENOENT)
> +		if (errno == ENOENT)
>  			return 0;
>  		else
>  			return -1;
> diff --git a/files.c b/files.c
> index 3e934c8..1b09244 100644
> --- a/files.c
> +++ b/files.c
> @@ -598,7 +598,7 @@ int prepare_fd_pid(struct pstree_item *item)
>  	if (!fdinfo_per_id) {
>  		fdinfo_fd = open_image(CR_FD_FDINFO, O_RSTR | O_OPT, pid);
>  		if (fdinfo_fd < 0) {
> -			if (fdinfo_fd == -ENOENT)
> +			if (errno == ENOENT)
>  				return 0;
>  			return -1;
>  		}
> @@ -1086,7 +1086,7 @@ int prepare_fs_pid(struct pstree_item *item)
>  
>  	ifd = open_image(CR_FD_FS, O_RSTR | O_OPT, pid);
>  	if (ifd < 0) {
> -		if (ifd == -ENOENT)
> +		if (errno == ENOENT)
>  			goto ok;
>  		else
>  			goto out;
> diff --git a/irmap.c b/irmap.c
> index 17d3c14..388e473 100644
> --- a/irmap.c
> +++ b/irmap.c
> @@ -381,7 +381,7 @@ in:
>  		return 1;
>  	}
>  
> -	if (*fd == -ENOENT && dir == AT_FDCWD) {
> +	if (errno == ENOENT && dir == AT_FDCWD) {
>  		pr_info("Searching irmap cache in parent\n");
>  		dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
>  		if (dir >= 0)
> diff --git a/mem.c b/mem.c
> index 6df11ab..918437f 100644
> --- a/mem.c
> +++ b/mem.c
> @@ -389,7 +389,7 @@ int prepare_mm_pid(struct pstree_item *i)
>  
>  	fd = open_image(CR_FD_MM, O_RSTR | O_OPT, pid);
>  	if (fd < 0) {
> -		if (fd == -ENOENT)
> +		if (errno == ENOENT)
>  			return 0;
>  		return -1;
>  	}
> diff --git a/protobuf.c b/protobuf.c
> index f73fb28..c3ffcca 100644
> --- a/protobuf.c
> +++ b/protobuf.c
> @@ -642,7 +642,7 @@ int collect_image(struct collect_image_info *cinfo)
>  
>  	fd = open_image(cinfo->fd_type, O_RSTR | (optional ? O_OPT : 0));
>  	if (fd < 0) {
> -		if (optional && fd == -ENOENT)
> +		if (optional && errno == ENOENT)
>  			return 0;
>  		else
>  			return -1;
> -- 
> 1.8.4.2
> 
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list