[lxc-devel] [lxd/master] shared/utils: deal with symlinks

brauner on Github lxc-bot at linuxcontainers.org
Wed Dec 13 15:35:51 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171213/6d3f49e1/attachment.bin>
-------------- next part --------------
From d682c03a7d19a689763fa366b2816d9b6b3e54f6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 13 Dec 2017 16:34:48 +0100
Subject: [PATCH] shared/utils: deal with symlinks

Closes #4097.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 shared/util_linux.go | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/shared/util_linux.go b/shared/util_linux.go
index 78d782924..75b3a2678 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -336,6 +336,15 @@ func GetFileStat(p string) (uid int, gid int, major int, minor int,
 }
 
 func parseMountinfo(name string) int {
+	// In case someone uses symlinks we need to look for the actual
+	// mountpoint.
+	actualPath, err := filepath.EvalSymlinks(name)
+	if err != nil {
+		return -1
+	}
+
+	logger.Debugf("Path \"%s\" is pointing to \"%s\"", name, actualPath)
+
 	f, err := os.Open("/proc/self/mountinfo")
 	if err != nil {
 		return -1
@@ -350,8 +359,7 @@ func parseMountinfo(name string) int {
 			return -1
 		}
 		cleanPath := filepath.Clean(tokens[4])
-		cleanName := filepath.Clean(name)
-		if cleanPath == cleanName {
+		if cleanPath == actualPath {
 			return 1
 		}
 	}
@@ -361,8 +369,9 @@ func parseMountinfo(name string) int {
 
 func IsMountPoint(name string) bool {
 	ret := parseMountinfo(name)
-	if ret >= 0 {
-		return (ret == 1)
+	if ret == 1 {
+		logger.Debugf("Detected that \"%s\" is a mountpoint", name)
+		return true
 	}
 
 	stat, err := os.Stat(name)


More information about the lxc-devel mailing list