2014-02-21 02:27:42 +00:00
|
|
|
package nsinit
|
2014-02-19 00:56:11 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
2014-02-20 00:40:36 +00:00
|
|
|
"syscall"
|
2014-02-19 00:56:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var namespaceMap = map[libcontainer.Namespace]int{
|
2014-02-20 00:40:36 +00:00
|
|
|
libcontainer.CLONE_NEWNS: syscall.CLONE_NEWNS,
|
|
|
|
libcontainer.CLONE_NEWUTS: syscall.CLONE_NEWUTS,
|
|
|
|
libcontainer.CLONE_NEWIPC: syscall.CLONE_NEWIPC,
|
|
|
|
libcontainer.CLONE_NEWUSER: syscall.CLONE_NEWUSER,
|
|
|
|
libcontainer.CLONE_NEWPID: syscall.CLONE_NEWPID,
|
|
|
|
libcontainer.CLONE_NEWNET: syscall.CLONE_NEWNET,
|
2014-02-19 00:56:11 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 06:43:40 +00:00
|
|
|
// namespaceFileMap is used to convert the libcontainer types
|
|
|
|
// into the names of the files located in /proc/<pid>/ns/* for
|
|
|
|
// each namespace
|
2014-02-20 03:53:25 +00:00
|
|
|
var namespaceFileMap = map[libcontainer.Namespace]string{
|
|
|
|
libcontainer.CLONE_NEWNS: "mnt",
|
|
|
|
libcontainer.CLONE_NEWUTS: "uts",
|
|
|
|
libcontainer.CLONE_NEWIPC: "ipc",
|
|
|
|
libcontainer.CLONE_NEWUSER: "user",
|
|
|
|
libcontainer.CLONE_NEWPID: "pid",
|
|
|
|
libcontainer.CLONE_NEWNET: "net",
|
|
|
|
}
|
|
|
|
|
2014-02-19 07:13:36 +00:00
|
|
|
// getNamespaceFlags parses the container's Namespaces options to set the correct
|
|
|
|
// flags on clone, unshare, and setns
|
2014-02-22 01:11:57 +00:00
|
|
|
func GetNamespaceFlags(namespaces libcontainer.Namespaces) (flag int) {
|
2014-02-19 07:13:36 +00:00
|
|
|
for _, ns := range namespaces {
|
|
|
|
flag |= namespaceMap[ns]
|
|
|
|
}
|
2014-02-19 22:33:25 +00:00
|
|
|
return flag
|
2014-02-19 07:13:36 +00:00
|
|
|
}
|