namespaces_syscall.go 751 B

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