From 0d2d52339058a19e66ecc75f78c52596054c7dad Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 29 Apr 2019 11:21:55 +0200 Subject: top: fallback to execing ps(1) Fallback to executing ps(1) in case we hit an unknown psgo descriptor. This ensures backwards compatibility with docker-top, which was purely ps(1) driven. Also support comma-separated descriptors as input. Signed-off-by: Valentin Rothberg --- libpod/container_top_linux.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'libpod') diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go index b370495fe..392a7029e 100644 --- a/libpod/container_top_linux.go +++ b/libpod/container_top_linux.go @@ -20,14 +20,24 @@ func (c *Container) Top(descriptors []string) ([]string, error) { if conStat != ContainerStateRunning { return nil, errors.Errorf("top can only be used on running containers") } - return c.GetContainerPidInformation(descriptors) + + // Also support comma-separated input. + psgoDescriptors := []string{} + for _, d := range descriptors { + for _, s := range strings.Split(d, ",") { + if s != "" { + psgoDescriptors = append(psgoDescriptors, s) + } + } + } + return c.GetContainerPidInformation(psgoDescriptors) } // GetContainerPidInformation returns process-related data of all processes in // the container. The output data can be controlled via the `descriptors` // argument which expects format descriptors and supports all AIXformat // descriptors of ps (1) plus some additional ones to for instance inspect the -// set of effective capabilities. Eeach element in the returned string slice +// set of effective capabilities. Each element in the returned string slice // is a tab-separated string. // // For more details, please refer to github.com/containers/psgo. -- cgit v1.2.3-54-g00ecf