namespaces_syscall.go 734 B

123456789101112131415161718192021222324252627282930313233
  1. // +build linux
  2. package configs
  3. import "golang.org/x/sys/unix"
  4. func (n *Namespace) Syscall() int {
  5. return namespaceInfo[n.Type]
  6. }
  7. var namespaceInfo = map[NamespaceType]int{
  8. NEWNET: unix.CLONE_NEWNET,
  9. NEWNS: unix.CLONE_NEWNS,
  10. NEWUSER: unix.CLONE_NEWUSER,
  11. NEWIPC: unix.CLONE_NEWIPC,
  12. NEWUTS: unix.CLONE_NEWUTS,
  13. NEWPID: unix.CLONE_NEWPID,
  14. NEWCGROUP: unix.CLONE_NEWCGROUP,
  15. }
  16. // CloneFlags parses the container's Namespaces options to set the correct
  17. // flags on clone, unshare. This function returns flags only for new namespaces.
  18. func (n *Namespaces) CloneFlags() uintptr {
  19. var flag int
  20. for _, v := range *n {
  21. if v.Path != "" {
  22. continue
  23. }
  24. flag |= namespaceInfo[v.Type]
  25. }
  26. return uintptr(flag)
  27. }