github.com/rish1988/moby@v25.0.2+incompatible/testutil/daemon/daemon_linux.go (about) 1 package daemon // import "github.com/docker/docker/testutil/daemon" 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 "testing" 9 10 "golang.org/x/sys/unix" 11 "gotest.tools/v3/assert" 12 ) 13 14 func cleanupNetworkNamespace(t testing.TB, d *Daemon) { 15 t.Helper() 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 filepath.WalkDir(filepath.Join(d.execRoot, "netns"), func(path string, _ os.DirEntry, _ error) error { 22 if err := unix.Unmount(path, unix.MNT_DETACH); err != nil && err != unix.EINVAL && err != unix.ENOENT { 23 t.Logf("[%s] unmount of %s failed: %v", d.id, path, err) 24 } 25 os.Remove(path) 26 return nil 27 }) 28 } 29 30 // CgroupNamespace returns the cgroup namespace the daemon is running in 31 func (d *Daemon) CgroupNamespace(t testing.TB) string { 32 link, err := os.Readlink(fmt.Sprintf("/proc/%d/ns/cgroup", d.Pid())) 33 assert.NilError(t, err) 34 35 return strings.TrimSpace(link) 36 }