summaryrefslogtreecommitdiff
path: root/pkg/adapter
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-01-15 23:33:10 +0100
committerGitHub <noreply@github.com>2020-01-15 23:33:10 +0100
commit741e29caf39c57551724a48265f6d9641f8f6fe0 (patch)
tree402ec832106bdc4da02fcc30927c465152b1fe72 /pkg/adapter
parent0870e88ff48eaf6b5624044b7cd2bc35cff85150 (diff)
parent69bd57f518cbc7c97808a663d76066d0d247ac0f (diff)
downloadpodman-741e29caf39c57551724a48265f6d9641f8f6fe0.tar.gz
podman-741e29caf39c57551724a48265f6d9641f8f6fe0.tar.bz2
podman-741e29caf39c57551724a48265f6d9641f8f6fe0.zip
Merge pull request #4860 from vrothberg/v2-top
v2 api: top improvements
Diffstat (limited to 'pkg/adapter')
-rw-r--r--pkg/adapter/containers.go67
1 files changed, 1 insertions, 66 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index 8b21d6b94..f66999ffa 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -27,7 +27,6 @@ import (
"github.com/containers/libpod/libpod/logs"
"github.com/containers/libpod/pkg/adapter/shortcuts"
"github.com/containers/libpod/pkg/systemdgen"
- "github.com/containers/psgo"
"github.com/containers/storage"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -913,71 +912,7 @@ func (r *LocalRuntime) Top(cli *cliconfig.TopValues) ([]string, error) {
return nil, errors.Wrapf(err, "unable to lookup requested container")
}
- output, psgoErr := container.Top(descriptors)
- if psgoErr == nil {
- return output, nil
- }
-
- // If we encountered an ErrUnknownDescriptor error, fallback to executing
- // ps(1). This ensures backwards compatibility to users depending on ps(1)
- // and makes sure we're ~compatible with docker.
- if errors.Cause(psgoErr) != psgo.ErrUnknownDescriptor {
- return nil, psgoErr
- }
-
- output, err = r.execPS(container, descriptors)
- if err != nil {
- // Note: return psgoErr to guide users into using the AIX descriptors
- // instead of using ps(1).
- return nil, psgoErr
- }
-
- // Trick: filter the ps command from the output instead of
- // checking/requiring PIDs in the output.
- filtered := []string{}
- cmd := strings.Join(descriptors, " ")
- for _, line := range output {
- if !strings.Contains(line, cmd) {
- filtered = append(filtered, line)
- }
- }
-
- return filtered, nil
-}
-
-func (r *LocalRuntime) execPS(c *libpod.Container, args []string) ([]string, error) {
- rPipe, wPipe, err := os.Pipe()
- if err != nil {
- return nil, err
- }
- defer wPipe.Close()
- defer rPipe.Close()
-
- streams := new(libpod.AttachStreams)
- streams.OutputStream = wPipe
- streams.ErrorStream = wPipe
- streams.InputStream = bufio.NewReader(os.Stdin)
- streams.AttachOutput = true
- streams.AttachError = true
- streams.AttachInput = true
-
- psOutput := []string{}
- go func() {
- scanner := bufio.NewScanner(rPipe)
- for scanner.Scan() {
- psOutput = append(psOutput, scanner.Text())
- }
- }()
-
- cmd := append([]string{"ps"}, args...)
- ec, err := c.Exec(false, false, map[string]string{}, cmd, "", "", streams, 0, nil, "")
- if err != nil {
- return nil, err
- } else if ec != 0 {
- return nil, errors.Errorf("Runtime failed with exit status: %d and output: %s", ec, strings.Join(psOutput, " "))
- }
-
- return psOutput, nil
+ return container.Top(descriptors)
}
// ExecContainer executes a command in the container