[CRIU] [PATCH] ipc_ns: close file immediately when we don't need it

Huang Qiang h.huangqiang at huawei.com
Thu Oct 25 04:37:41 EDT 2012


Hi Andrew,
According to your advice, I just found this one place to change, the other
places, do you mean such like prepare_ipc_msg()?
I see close_safe() will change the errno, but in the error's way, we return
the errno exactly what we set to ret, so that won't be confused.

Or if you mean we shouldn't use "return close_safe(&fd)" style, as we don't
want the close file fault disturb us? If so, I'll send another patch to fix it.

On 2012/10/25 16:14, Huang Qiang wrote:
> According to Andrew's advice, change the close file logic a bit, to
> make the code seems more readable.
> 
> Signed-off-by: Huang Qiang <h.huangqiang at huawei.com>
> ---
>  ipc_ns.c |   13 +++++--------
>  1 files changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/ipc_ns.c b/ipc_ns.c
> index d006b3d..d31f162 100644
> --- a/ipc_ns.c
> +++ b/ipc_ns.c
> @@ -876,10 +876,10 @@ static int prepare_ipc_var(int pid)
>  		return -1;
> 
>  	ret = pb_read_one(fd, &var, PB_IPCNS_VAR);
> +	close_safe(&fd);
>  	if (ret <= 0) {
>  		pr_err("Failed to read IPC namespace variables\n");
> -		ret = -EFAULT;
> -		goto err;
> +		return -EFAULT;
>  	}
> 
>  	ipc_sysctl_req(var, CTL_PRINT);
> @@ -889,13 +889,10 @@ static int prepare_ipc_var(int pid)
> 
>  	if (ret < 0) {
>  		pr_err("Failed to prepare IPC namespace variables\n");
> -		ret = -EFAULT;
> -		goto err;
> +		return -EFAULT;
>  	}
> -	return close_safe(&fd);
> -err:
> -	close_safe(&fd);
> -	return ret;
> +
> +	return 0;
>  }
> 
>  int prepare_ipc_ns(int pid)
> -- 1.7.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://openvz.org/mailman/listinfo/criu
> 
> 




More information about the CRIU mailing list