The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3944

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 60321ae737a0377ca611f61b4b6454b4ce858242 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Fri, 13 Oct 2017 19:57:17 -0400
Subject: [PATCH] shared/util: More snap handling logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 shared/util.go | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/shared/util.go b/shared/util.go
index 260b32c8a..dd091c86e 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -104,8 +104,8 @@ func IsUnixSocket(path string) bool {
 // On a normal system, this does nothing
 // When inside of a snap environment, returns the real path
 func HostPath(path string) string {
-       // Ignore relative paths
-       if len(path) == 0 || path[0] != os.PathSeparator {
+       // Ignore empty paths
+       if len(path) == 0  {
                return path
        }
 
@@ -115,6 +115,22 @@ func HostPath(path string) string {
                return path
        }
 
+       // Handle relative paths
+       if path[0] != os.PathSeparator {
+               // Use the cwd of the parent as snap-confine alters our own cwd 
on launch
+               ppid := os.Getppid()
+               if ppid < 1 {
+                       return path
+               }
+
+               pwd, err := os.Readlink(fmt.Sprintf("/proc/%d/cwd", ppid))
+               if err != nil {
+                       return path
+               }
+
+               path = filepath.Clean(strings.Join([]string{pwd, path}, 
string(os.PathSeparator)))
+       }
+
        // Check if the path is already snap-aware
        for _, prefix := range []string{"/snap", "/var/snap", "/var/lib/snapd"} 
{
                if strings.HasPrefix(path, prefix) {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to