[CRIU] [PATCH 1/2] files: restore cwd after switching mntns

Pavel Emelyanov xemul at parallels.com
Thu Nov 19 04:23:30 PST 2015


On 11/18/2015 02:04 PM, Andrey Vagin wrote:
> From: Andrew Vagin <avagin at virtuozzo.com>

Comment required.

> Cc: Stanislav Kinsbursky <skinsbursky at openvz.org>
> Reported-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
> Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
> ---
>  files-reg.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/files-reg.c b/files-reg.c
> index 1e2daa9..ac334e7 100644
> --- a/files-reg.c
> +++ b/files-reg.c
> @@ -423,6 +423,7 @@ void try_clean_remaps(int ns_fd)
>  {
>  	struct remap_info *ri;
>  	int old_ns = -1;
> +	int cwd_fd = -1;
>  
>  	if (list_empty(&remaps))
>  		goto out;
> @@ -436,6 +437,12 @@ void try_clean_remaps(int ns_fd)
>  			return;
>  		}
>  
> +		cwd_fd = open(".", O_DIRECTORY);
> +		if (cwd_fd < 0) {
> +			pr_perror("Unable to open cwd");
> +			return;
> +		}
> +
>  		if (setns(ns_fd, CLONE_NEWNS) < 0) {
>  			close(old_ns);
>  			pr_perror("`- Can't switch");
> @@ -453,6 +460,15 @@ void try_clean_remaps(int ns_fd)
>  		close(old_ns);
>  	}
>  
> +	if (cwd_fd >= 0) {
> +		if (fchdir(cwd_fd)) {
> +			pr_perror("Unable to restore cwd");
> +			close(cwd_fd);
> +			return;
> +		}
> +		close(cwd_fd);
> +	}
> +
>  out:
>  	if (ns_fd >= 0)
>  		close(ns_fd);
> 



More information about the CRIU mailing list