[lxc-devel] [lxd/master] Fix hostpath handling

stgraber on Github lxc-bot at linuxcontainers.org
Sat Jan 20 20:59:23 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180120/8e965f0f/attachment.bin>
-------------- next part --------------
From f0c5e424d37bea46101bd65881afe2aed496eae4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sat, 20 Jan 2018 22:56:47 +0200
Subject: [PATCH 1/2] shared/hostpath: Also check SNAP_NAME
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4183

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/util.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/shared/util.go b/shared/util.go
index e039905f0..08884bf60 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -116,7 +116,8 @@ func HostPath(path string) string {
 
 	// Check if we're running in a snap package
 	snap := os.Getenv("SNAP")
-	if snap == "" {
+	snapName := os.Getenv("SNAP_NAME")
+	if snap == "" || snapName != "lxd" {
 		return path
 	}
 

From 4afc3c7f00241cd106f49d87f8d78ef775aee8df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sat, 20 Jan 2018 22:58:38 +0200
Subject: [PATCH 2/2] shared/hostpath: Properly handle prefix check
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4181

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/util.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/shared/util.go b/shared/util.go
index 08884bf60..3efea2e6e 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -139,7 +139,7 @@ func HostPath(path string) string {
 
 	// Check if the path is already snap-aware
 	for _, prefix := range []string{"/dev", "/snap", "/var/snap", "/var/lib/snapd"} {
-		if strings.HasPrefix(path, prefix) {
+		if path == prefix || strings.HasPrefix(path, fmt.Printf("%s/", prefix)) {
 			return path
 		}
 	}


More information about the lxc-devel mailing list