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

Submitted by Pavel Tikhomirov on Sept. 11, 2018, 8:09 a.m.

Details

Message ID 20180911080906.4555-6-ptikhomirov@virtuozzo.com
State Accepted
Series "minor fixes related to paths and logs"
Headers show

Commit Message

Pavel Tikhomirov Sept. 11, 2018, 8:09 a.m.
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 criu/files-reg.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

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;