MCPcopy
hub / github.com/opencontainers/runc / IsNamespaceSupported

Function IsNamespaceSupported

libcontainer/configs/namespaces_linux.go:51–71  ·  view source on GitHub ↗

IsNamespaceSupported returns whether a namespace is available or not

(ns NamespaceType)

Source from the content-addressed store, hash-verified

49// IsNamespaceSupported returns whether a namespace is available or
50// not
51func IsNamespaceSupported(ns NamespaceType) bool {
52 nsLock.Lock()
53 defer nsLock.Unlock()
54 supported, ok := supportedNamespaces[ns]
55 if ok {
56 return supported
57 }
58 nsFile := NsName(ns)
59 // if the namespace type is unknown, just return false
60 if nsFile == "" {
61 return false
62 }
63 // We don't need to use /proc/thread-self here because the list of
64 // namespace types is unrelated to the thread. This lets us avoid having to
65 // do runtime.LockOSThread.
66 _, err := os.Stat("/proc/self/ns/" + nsFile)
67 // a namespace is supported if it exists and we have permissions to read it
68 supported = err == nil
69 supportedNamespaces[ns] = supported
70 return supported
71}
72
73func NamespaceTypes() []NamespaceType {
74 return []NamespaceType{

Callers 3

criuNotificationsMethod · 0.92
currentStateMethod · 0.92
orderNamespacePathsMethod · 0.92

Calls 1

NsNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…