namespaces_syscall.go 692 B

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