utils.go 895 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // +build linux
  2. package namespaces
  3. import (
  4. "os"
  5. "syscall"
  6. )
  7. type initError struct {
  8. Message string `json:"message,omitempty"`
  9. }
  10. func (i initError) Error() string {
  11. return i.Message
  12. }
  13. // New returns a newly initialized Pipe for communication between processes
  14. func newInitPipe() (parent *os.File, child *os.File, err error) {
  15. fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM|syscall.SOCK_CLOEXEC, 0)
  16. if err != nil {
  17. return nil, nil, err
  18. }
  19. return os.NewFile(uintptr(fds[1]), "parent"), os.NewFile(uintptr(fds[0]), "child"), nil
  20. }
  21. // GetNamespaceFlags parses the container's Namespaces options to set the correct
  22. // flags on clone, unshare, and setns
  23. func GetNamespaceFlags(namespaces map[string]bool) (flag int) {
  24. for key, enabled := range namespaces {
  25. if enabled {
  26. if ns := GetNamespace(key); ns != nil {
  27. flag |= ns.Value
  28. }
  29. }
  30. }
  31. return flag
  32. }