summaryrefslogtreecommitdiff
path: root/cmd/podman/attach.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-10 08:51:26 -0700
committerGitHub <noreply@github.com>2019-04-10 08:51:26 -0700
commit1fb0a09591ae86b659dc87bd9e3f7fe29d8add8d (patch)
tree0f9df726674f9a28abbd08fc2aa9bfb71509ec1e /cmd/podman/attach.go
parent1701707dad4e4dba9d4331bd8917be28d138254d (diff)
parentfbcda7772d9fb7667be3a26fbabea0a7b5ea9a58 (diff)
downloadpodman-1fb0a09591ae86b659dc87bd9e3f7fe29d8add8d.tar.gz
podman-1fb0a09591ae86b659dc87bd9e3f7fe29d8add8d.tar.bz2
podman-1fb0a09591ae86b659dc87bd9e3f7fe29d8add8d.zip
Merge pull request #2874 from baude/varlinkterm
Add the ability to attach remotely to a container
Diffstat (limited to 'cmd/podman/attach.go')
-rw-r--r--cmd/podman/attach.go48
1 files changed, 8 insertions, 40 deletions
diff --git a/cmd/podman/attach.go b/cmd/podman/attach.go
index f326f53c3..2fa05a3b1 100644
--- a/cmd/podman/attach.go
+++ b/cmd/podman/attach.go
@@ -1,11 +1,7 @@
package main
import (
- "os"
-
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
- "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -39,49 +35,21 @@ func init() {
flags.BoolVar(&attachCommand.SigProxy, "sig-proxy", true, "Proxy received signals to the process")
flags.BoolVarP(&attachCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
markFlagHiddenForRemoteClient("latest", flags)
+ // TODO allow for passing of a new deatch keys
+ markFlagHiddenForRemoteClient("detach-keys", flags)
}
func attachCmd(c *cliconfig.AttachValues) error {
- args := c.InputArgs
- var ctr *libpod.Container
-
if len(c.InputArgs) > 1 || (len(c.InputArgs) == 0 && !c.Latest) {
return errors.Errorf("attach requires the name or id of one running container or the latest flag")
}
-
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
- if err != nil {
- return errors.Wrapf(err, "error creating libpod runtime")
- }
- defer runtime.Shutdown(false)
-
- if c.Latest {
- ctr, err = runtime.GetLatestContainer()
- } else {
- ctr, err = runtime.LookupContainer(args[0])
- }
-
- if err != nil {
- return errors.Wrapf(err, "unable to exec into %s", args[0])
+ if remoteclient && len(c.InputArgs) != 1 {
+ return errors.Errorf("attach requires the name or id of one running container")
}
-
- conState, err := ctr.State()
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
- return errors.Wrapf(err, "unable to determine state of %s", args[0])
- }
- if conState != libpod.ContainerStateRunning {
- return errors.Errorf("you can only attach to running containers")
- }
-
- inputStream := os.Stdin
- if c.NoStdin {
- inputStream = nil
+ return errors.Wrapf(err, "error creating runtime")
}
-
- // If the container is in a pod, also set to recursively start dependencies
- if err := adapter.StartAttachCtr(getContext(), ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, c.SigProxy, false, ctr.PodID() != ""); err != nil && errors.Cause(err) != libpod.ErrDetach {
- return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
- }
-
- return nil
+ defer runtime.Shutdown(false)
+ return runtime.Attach(getContext(), c)
}