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

Andrey Vagin avagin at openvz.org
Fri Feb 21 10:00:40 PST 2014


v2: don't use snprintf
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/mount.c b/mount.c
index eeba090..7149ec2 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, "./"));
 }
 
 /* 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,13 @@ 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  = strlen(me->mountpoint) + 2;
+		pm->mountpoint = xmalloc(len);
 		if (!pm->mountpoint)
 			goto err;
+		pm->mountpoint[0] = '.';
+		strcpy(pm->mountpoint + 1, me->mountpoint);
 
 		pr_debug("\t\tGetting source for %d\n", pm->mnt_id);
 		pm->source = xstrdup(me->source);
-- 
1.8.5.3



More information about the CRIU mailing list