pkg/ns: fixed the check for network namespace path.

The expectation on older kernels (< 3.19) was to have the network
namespace always be a directory. This is not true if the network
namespace is bind mounted to a file, and will make the plugin fail
erroneously in such cases. The fix is to remove this assumption
completely and just do a basic check on the file system types being
returned.

Fixes #288
This commit is contained in:
Avinash Sridharan 2016-08-24 23:49:50 +00:00
parent 5c3c171642
commit 7281d5792a

View File

@ -20,7 +20,6 @@ import (
"os"
"path"
"runtime"
"strings"
"sync"
"syscall"
@ -101,19 +100,7 @@ func IsNSorErr(nspath string) error {
}
switch stat.Type {
case PROCFS_MAGIC:
// Kernel < 3.19
validPathContent := "ns/"
validName := strings.Contains(nspath, validPathContent)
if !validName {
return NSPathNotNSErr{msg: fmt.Sprintf("path %q doesn't contain %q", nspath, validPathContent)}
}
return nil
case NSFS_MAGIC:
// Kernel >= 3.19
case PROCFS_MAGIC, NSFS_MAGIC:
return nil
default:
return NSPathNotNSErr{msg: fmt.Sprintf("unknown FS magic on %q: %x", nspath, stat.Type)}