2015-04-25 06:09:56 +08:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package configs
|
|
|
|
|
2017-05-10 05:38:27 +08:00
|
|
|
import "golang.org/x/sys/unix"
|
2015-04-25 06:09:56 +08:00
|
|
|
|
|
|
|
func (n *Namespace) Syscall() int {
|
|
|
|
return namespaceInfo[n.Type]
|
|
|
|
}
|
|
|
|
|
|
|
|
var namespaceInfo = map[NamespaceType]int{
|
2017-05-10 05:38:27 +08:00
|
|
|
NEWNET: unix.CLONE_NEWNET,
|
|
|
|
NEWNS: unix.CLONE_NEWNS,
|
|
|
|
NEWUSER: unix.CLONE_NEWUSER,
|
|
|
|
NEWIPC: unix.CLONE_NEWIPC,
|
|
|
|
NEWUTS: unix.CLONE_NEWUTS,
|
|
|
|
NEWPID: unix.CLONE_NEWPID,
|
2015-04-25 06:09:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CloneFlags parses the container's Namespaces options to set the correct
|
2016-03-25 11:11:48 +08:00
|
|
|
// flags on clone, unshare. This function returns flags only for new namespaces.
|
2015-04-25 06:09:56 +08:00
|
|
|
func (n *Namespaces) CloneFlags() uintptr {
|
|
|
|
var flag int
|
|
|
|
for _, v := range *n {
|
|
|
|
if v.Path != "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
flag |= namespaceInfo[v.Type]
|
|
|
|
}
|
|
|
|
return uintptr(flag)
|
|
|
|
}
|