diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2019-04-29 11:21:55 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2019-05-03 11:20:16 +0200 |
commit | 0d2d52339058a19e66ecc75f78c52596054c7dad (patch) | |
tree | 73636772d105d249a996ee145b0afd48fddf16ab /libpod | |
parent | d9d9c82184ad6d7e3fad07dfe2e99b158560d3a8 (diff) | |
download | podman-0d2d52339058a19e66ecc75f78c52596054c7dad.tar.gz podman-0d2d52339058a19e66ecc75f78c52596054c7dad.tar.bz2 podman-0d2d52339058a19e66ecc75f78c52596054c7dad.zip |
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 <rothberg@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_top_linux.go | 14 |
1 files changed, 12 insertions, 2 deletions
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. |