diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index 32142edb..d00e0e2e 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -329,21 +329,18 @@ func GetPids(path string) ([]int, error) { var pids []int // collect pids from all sub-cgroups err := filepath.Walk(path, func(p string, info os.FileInfo, iErr error) error { - if info.IsDir() { + dir, file := filepath.Split(p) + if file != "cgroup.procs" { return nil } - - dir, file := filepath.Split(p) - if file == "cgroup.procs" { - if iErr != nil { - return iErr - } - cPids, err := readProcsFile(dir) - if err != nil { - return err - } - pids = append(pids, cPids...) + if iErr != nil { + return iErr } + cPids, err := readProcsFile(dir) + if err != nil { + return err + } + pids = append(pids, cPids...) return nil }) return pids, err diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index 267c0731..00306f17 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -1250,3 +1250,29 @@ func TestRootfsPropagationSharedMount(t *testing.T) { t.Fatalf("Mount in container on %s did not propagate to host on %s. finmnt output=%s", dir2cont, dir2host, outtrim) } } + +func TestPIDHost(t *testing.T) { + if testing.Short() { + return + } + + rootfs, err := newRootfs() + ok(t, err) + defer remove(rootfs) + + l, err := os.Readlink("/proc/1/ns/pid") + ok(t, err) + + config := newTemplateConfig(rootfs) + config.Namespaces.Remove(configs.NEWPID) + buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/pid") + ok(t, err) + + if exitCode != 0 { + t.Fatalf("exit code not 0. code %d stderr %q", exitCode, buffers.Stderr) + } + + if actual := strings.Trim(buffers.Stdout.String(), "\n"); actual != l { + t.Fatalf("ipc link not equal to host link %q %q", actual, l) + } +}