summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_top.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-03-17 21:46:37 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-03-18 11:40:22 +0100
commit46b74a8ff8dea146539fa731cc5746fc5a59e186 (patch)
treeb84efa30a63a9f2b06761a07aeadc9b84b7e7935 /cmd/podman/pod_top.go
parent8aed32acea9bb35898abcee58fc9aa2a03ef264a (diff)
downloadpodman-46b74a8ff8dea146539fa731cc5746fc5a59e186.tar.gz
podman-46b74a8ff8dea146539fa731cc5746fc5a59e186.tar.bz2
podman-46b74a8ff8dea146539fa731cc5746fc5a59e186.zip
rootless: fix pod top
we need to join the namespace of the target pod. Closes: https://github.com/containers/libpod/issues/2682 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'cmd/podman/pod_top.go')
-rw-r--r--cmd/podman/pod_top.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/podman/pod_top.go b/cmd/podman/pod_top.go
index c9a6d8822..f65d66df6 100644
--- a/cmd/podman/pod_top.go
+++ b/cmd/podman/pod_top.go
@@ -9,6 +9,7 @@ import (
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -53,6 +54,10 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
)
args := c.InputArgs
+ if os.Geteuid() != 0 {
+ rootless.SetSkipStorageSetup(true)
+ }
+
if c.ListDescriptors {
descriptors, err := libpod.GetContainerPidInformationDescriptors()
if err != nil {
@@ -77,6 +82,27 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
} else {
descriptors = args[1:]
}
+
+ if os.Geteuid() != 0 {
+ var pod *adapter.Pod
+ var err error
+ if c.Latest {
+ pod, err = runtime.GetLatestPod()
+ } else {
+ pod, err = runtime.LookupPod(c.InputArgs[0])
+ }
+ if err != nil {
+ return errors.Wrapf(err, "unable to lookup requested container")
+ }
+ became, ret, err := runtime.JoinOrCreateRootlessPod(pod)
+ if err != nil {
+ return err
+ }
+ if became {
+ os.Exit(ret)
+ }
+ }
+
w := tabwriter.NewWriter(os.Stdout, 5, 1, 3, ' ', 0)
psOutput, err := runtime.PodTop(c, descriptors)
if err != nil {