IsNamespaceSupported returns whether a namespace is available or not
(ns NamespaceType)
| 49 | // IsNamespaceSupported returns whether a namespace is available or |
| 50 | // not |
| 51 | func 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 | |
| 73 | func NamespaceTypes() []NamespaceType { |
| 74 | return []NamespaceType{ |
no test coverage detected
searching dependent graphs…