[CRIU] [PATCH 2/5] mounts: use relative paths for mountpoints

Pavel Emelyanov xemul at parallels.com
Sat Feb 22 00:49:26 PST 2014


On 02/21/2014 05:51 PM, Andrey Vagin wrote:

This comment sucks.

> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  mount.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/mount.c b/mount.c
> index 4d66dd9..d315e4c 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -47,7 +47,7 @@ static int validate_mounts(struct mount_info *info, bool call_plugins);
>  
>  static inline int is_root(char *p)
>  {
> -	return p[0] == '/' && p[1] == '\0';
> +	return (!strcmp(p, "/") || !strcmp(p, "./"));

Why || ? Do we have both types of paths?

>  }
>  
>  /* True for the root mount (the topmost one) */
> @@ -78,7 +78,7 @@ int open_mount(unsigned int s_dev)
>  			if (mntns_root == -1) {
>  				pr_debug("mpopen %s\n", i->mountpoint);
>  				return open(i->mountpoint, O_RDONLY);
> -			} else if (i->mountpoint[1] == '\0') {
> +			} else if (is_root_mount(i)) {
>  				pr_debug("mpopen root\n");
>  				return dup(mntns_root);
>  			} else {
> @@ -1361,6 +1361,7 @@ static struct mount_info *read_mnt_ns_img(int ns_pid)
>  
>  	while (1) {
>  		struct mount_info *pm;
> +		int len;
>  
>  		ret = pb_read_one_eof(img, &me, PB_MNT);
>  		if (ret <= 0)
> @@ -1389,10 +1390,12 @@ static struct mount_info *read_mnt_ns_img(int ns_pid)
>  		if (!pm->root)
>  			goto err;
>  
> -		pr_debug("\t\tGetting mpt for %d\n", pm->mnt_id);
> -		pm->mountpoint = xstrdup(me->mountpoint);
> +		pr_debug("\t\tGetting mpt for %d:%s\n", pm->mnt_id, me->mountpoint);
> +		len  = snprintf(NULL, 0, ".%s", me->mountpoint) + 1;
> +		pm->mountpoint = xmalloc(len);
>  		if (!pm->mountpoint)
>  			goto err;
> +		snprintf(pm->mountpoint, len, ".%s", me->mountpoint);
>  
>  		pr_debug("\t\tGetting source for %d\n", pm->mnt_id);
>  		pm->source = xstrdup(me->source);
> 




More information about the CRIU mailing list