daemon_unix.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // +build !windows
  2. package daemon // import "github.com/docker/docker/internal/test/daemon"
  3. import (
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. "github.com/docker/docker/internal/test"
  9. "golang.org/x/sys/unix"
  10. "gotest.tools/assert"
  11. )
  12. func cleanupNetworkNamespace(t testingT, execRoot string) {
  13. if ht, ok := t.(test.HelperT); ok {
  14. ht.Helper()
  15. }
  16. // Cleanup network namespaces in the exec root of this
  17. // daemon because this exec root is specific to this
  18. // daemon instance and has no chance of getting
  19. // cleaned up when a new daemon is instantiated with a
  20. // new exec root.
  21. netnsPath := filepath.Join(execRoot, "netns")
  22. filepath.Walk(netnsPath, func(path string, info os.FileInfo, err error) error {
  23. if err := unix.Unmount(path, unix.MNT_DETACH); err != nil && err != unix.EINVAL && err != unix.ENOENT {
  24. t.Logf("unmount of %s failed: %v", path, err)
  25. }
  26. os.Remove(path)
  27. return nil
  28. })
  29. }
  30. // CgroupNamespace returns the cgroup namespace the daemon is running in
  31. func (d *Daemon) CgroupNamespace(t assert.TestingT) string {
  32. link, err := os.Readlink(fmt.Sprintf("/proc/%d/ns/cgroup", d.Pid()))
  33. assert.NilError(t, err)
  34. return strings.TrimSpace(link)
  35. }
  36. // SignalDaemonDump sends a signal to the daemon to write a dump file
  37. func SignalDaemonDump(pid int) {
  38. unix.Kill(pid, unix.SIGQUIT)
  39. }
  40. func signalDaemonReload(pid int) error {
  41. return unix.Kill(pid, unix.SIGHUP)
  42. }