[CRIU] [PATCH 5/5] files: don't add double slash to path in create_ghost

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Sep 11 11:09:06 MSK 2018


Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/files-reg.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/criu/files-reg.c b/criu/files-reg.c
index c7fd7f35f..e3ed01f55 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -364,7 +364,13 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_im
 		goto err;
 	}
 
-	snprintf(path + ret, sizeof(path) - ret, "/%s", gf->remap.rpath);
+	/* Add a '/' only if we have no at the end */
+	if (path[root_len-1] != '/') {
+		path[root_len++] = '/';
+		path[root_len] = '\0';
+	}
+
+	snprintf(path + root_len, sizeof(path) - root_len, "%s", gf->remap.rpath);
 	ret = -1;
 again:
 	if (S_ISFIFO(gfe->mode)) {
@@ -399,7 +405,7 @@ static int create_ghost(struct ghost_file *gf, GhostFileEntry *gfe, struct cr_im
 		goto err;
 	}
 
-	strcpy(gf->remap.rpath, path + root_len + 1);
+	strcpy(gf->remap.rpath, path + root_len);
 	pr_debug("Remap rpath is %s\n", gf->remap.rpath);
 
 	ret = -1;
-- 
2.17.1



More information about the CRIU mailing list