|
@@ -136,30 +136,49 @@ func (n UTSMode) Valid() bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-// PidMode represents the pid stack of the container.
|
|
|
+// PidMode represents the pid namespace of the container.
|
|
|
type PidMode string
|
|
|
|
|
|
-// IsPrivate indicates whether the container uses its private pid stack.
|
|
|
+// IsPrivate indicates whether the container uses its own new pid namespace.
|
|
|
func (n PidMode) IsPrivate() bool {
|
|
|
- return !(n.IsHost())
|
|
|
+ return !(n.IsHost() || n.IsContainer())
|
|
|
}
|
|
|
|
|
|
-// IsHost indicates whether the container uses the host's pid stack.
|
|
|
+// IsHost indicates whether the container uses the host's pid namespace.
|
|
|
func (n PidMode) IsHost() bool {
|
|
|
return n == "host"
|
|
|
}
|
|
|
|
|
|
-// Valid indicates whether the pid stack is valid.
|
|
|
+// IsContainer indicates whether the container uses a container's pid namespace.
|
|
|
+func (n PidMode) IsContainer() bool {
|
|
|
+ parts := strings.SplitN(string(n), ":", 2)
|
|
|
+ return len(parts) > 1 && parts[0] == "container"
|
|
|
+}
|
|
|
+
|
|
|
+// Valid indicates whether the pid namespace is valid.
|
|
|
func (n PidMode) Valid() bool {
|
|
|
parts := strings.Split(string(n), ":")
|
|
|
switch mode := parts[0]; mode {
|
|
|
case "", "host":
|
|
|
+ case "container":
|
|
|
+ if len(parts) != 2 || parts[1] == "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
default:
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+// Container returns the name of the container whose pid namespace is going to be used.
|
|
|
+func (n PidMode) Container() string {
|
|
|
+ parts := strings.SplitN(string(n), ":", 2)
|
|
|
+ if len(parts) > 1 {
|
|
|
+ return parts[1]
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|
|
|
+
|
|
|
// DeviceMapping represents the device mapping between the host and the container.
|
|
|
type DeviceMapping struct {
|
|
|
PathOnHost string
|