From 7478e78ab777780843c09c8ae6458e24354b9fc9 Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Thu, 6 Apr 2017 16:45:05 +0100 Subject: [PATCH] Add NSPathByPidWithRoot The function is used in a case when /proc is bind mounted to other than /proc dir. --- net/netns.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/netns.go b/net/netns.go index 971baf63..3bd4a1c2 100644 --- a/net/netns.go +++ b/net/netns.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os/exec" + "path/filepath" "runtime" "github.com/vishvananda/netlink" @@ -80,5 +81,9 @@ func WithNetNSByPid(pid int, cmd string, args ...string) ([]byte, error) { } func NSPathByPid(pid int) string { - return fmt.Sprintf("/proc/%d/ns/net", pid) + return NSPathByPidWithRoot("/", pid) +} + +func NSPathByPidWithRoot(root string, pid int) string { + return filepath.Join(root, fmt.Sprintf("/proc/%d/ns/net", pid)) }