From 306a9477daa7b57ef62133bcf3f2f5966e26ffca Mon Sep 17 00:00:00 2001 From: Daniel Dao Date: Fri, 12 Feb 2021 12:36:33 +0000 Subject: return root pids with runsc ps `runsc ps` currently return pid for a task's immediate pid namespace, which is confusing when there're multiple pid namespaces. We should return only pids in the root namespace. Before: ``` 1000 1 0 0 ? 02:24 250ms chrome 1000 1 0 0 ? 02:24 40ms dumb-init 1000 1 0 0 ? 02:24 240ms chrome 1000 2 1 0 ? 02:24 2.78s node ``` After: ``` UID PID PPID C TTY STIME TIME CMD 1000 1 0 0 ? 12:35 0s dumb-init 1000 2 1 7 ? 12:35 240ms node 1000 13 2 21 ? 12:35 2.33s chrome 1000 27 13 3 ? 12:35 260ms chrome ``` Signed-off-by: Daniel Dao --- runsc/container/multi_container_test.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'runsc') diff --git a/runsc/container/multi_container_test.go b/runsc/container/multi_container_test.go index 17aef2121..b434cdb23 100644 --- a/runsc/container/multi_container_test.go +++ b/runsc/container/multi_container_test.go @@ -203,7 +203,7 @@ func TestMultiPIDNS(t *testing.T) { t.Errorf("failed to wait for sleep to start: %v", err) } expectedPL = []*control.Process{ - newProcessBuilder().PID(1).Cmd("sleep").Process(), + newProcessBuilder().PID(2).Cmd("sleep").Process(), } if err := waitForProcessList(containers[1], expectedPL); err != nil { t.Errorf("failed to wait for sleep to start: %v", err) @@ -291,16 +291,18 @@ func TestMultiPIDNSPath(t *testing.T) { if err := waitForProcessList(containers[0], expectedPL); err != nil { t.Errorf("failed to wait for sleep to start: %v", err) } - if err := waitForProcessList(containers[2], expectedPL); err != nil { - t.Errorf("failed to wait for sleep to start: %v", err) - } - expectedPL = []*control.Process{ newProcessBuilder().PID(2).PPID(0).Cmd("sleep").Process(), } if err := waitForProcessList(containers[1], expectedPL); err != nil { t.Errorf("failed to wait for sleep to start: %v", err) } + expectedPL = []*control.Process{ + newProcessBuilder().PID(3).PPID(0).Cmd("sleep").Process(), + } + if err := waitForProcessList(containers[2], expectedPL); err != nil { + t.Errorf("failed to wait for sleep to start: %v", err) + } // Root container runs in the root PID namespace and can see all // processes. @@ -371,14 +373,13 @@ func TestMultiPIDNSKill(t *testing.T) { const processes = 3 testSpecs, ids := createSpecs(cmd, cmd) - // TODO: Uncomment after https://github.com/google/gvisor/pull/5519. - //testSpecs[1].Linux = &specs.Linux{ - // Namespaces: []specs.LinuxNamespace{ - // { - // Type: "pid", - // }, - // }, - //} + testSpecs[1].Linux = &specs.Linux{ + Namespaces: []specs.LinuxNamespace{ + { + Type: "pid", + }, + }, + } containers, cleanup, err := startContainers(conf, testSpecs, ids) if err != nil { -- cgit v1.2.3