Add NSPathByPidWithRoot

The function is used in a case when /proc is bind mounted to
other than /proc dir.
This commit is contained in:
Martynas Pumputis authored and Bryan Boreham committed 2017-04-12 13:05:40 +00:00
1 parent 01bfa602ad
commit 7478e78ab7
1 file changed
+6 -1
+6 -1
View File
@@ -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))
}