[lxc-devel] [lxc/master] no rootfs => mounts always relative to host's /

brauner on Github lxc-bot at linuxcontainers.org
Wed Feb 3 17:03:41 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 470 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160203/22aeaad5/attachment.bin>
-------------- next part --------------
From 66436fbdee50347f45d24f568910448d31d3255c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at mailbox.org>
Date: Wed, 3 Feb 2016 13:17:51 +0100
Subject: [PATCH] no rootfs => mounts always relative to host's /

All lxc.mount.entry entries will be relative to the host's / when a container
does not have a rootfs.

Signed-off-by: Christian Brauner <christian.brauner at mailbox.org>
---
 src/lxc/conf.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index a32513d..1c0e7be 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1867,7 +1867,22 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
 
 static inline int mount_entry_on_systemfs(struct mntent *mntent)
 {
-	return mount_entry_on_generic(mntent, mntent->mnt_dir, NULL, NULL, NULL);
+	char path[MAXPATHLEN];
+	int ret;
+
+	/* For containers created without a rootfs all mounts are treated as
+	 * absolute paths starting at / on the host. */
+	if (mntent->mnt_dir[0] != '/')
+		ret = snprintf(path, sizeof(path), "/%s", mntent->mnt_dir);
+	else
+		ret = snprintf(path, sizeof(path), "%s", mntent->mnt_dir);
+
+	if (ret < 0 || ret >= sizeof(path)) {
+		ERROR("path name too long");
+		return -1;
+	}
+
+	return mount_entry_on_generic(mntent, path, NULL, NULL, NULL);
 }
 
 static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
@@ -1928,7 +1943,7 @@ static int mount_entry_on_relative_rootfs(struct mntent *mntent,
 
 	/* relative to root mount point */
 	ret = snprintf(path, sizeof(path), "%s/%s", rootfs->mount, mntent->mnt_dir);
-	if (ret >= sizeof(path)) {
+	if (ret < 0 || ret >= sizeof(path)) {
 		ERROR("path name too long");
 		return -1;
 	}


More information about the lxc-devel mailing list