summaryrefslogtreecommitdiff
path: root/cmd/podman/utils.go
diff options
context:
space:
mode:
authorMarco Vedovati <mvedovati@suse.com>2018-06-28 19:08:49 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-06 16:02:46 +0000
commit9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351 (patch)
treed028cdc8f75dbc7f0ffc741f412d3a47979a8645 /cmd/podman/utils.go
parentcf2be66f526fcd1ab9f7a1a3f9af6582070ef791 (diff)
downloadpodman-9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351.tar.gz
podman-9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351.tar.bz2
podman-9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351.zip
Refactor podman/utils with a single container start and attach function
Use a single function startAttachCtr() to handle both container start with attach and attach to running containers, as the code handling the attach is common for the 2 use cases. Signed-off-by: Marco Vedovati <mvedovati@suse.com> Closes: #1025 Approved by: rhatdan
Diffstat (limited to 'cmd/podman/utils.go')
-rw-r--r--cmd/podman/utils.go60
1 files changed, 6 insertions, 54 deletions
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index 72bdac256..21bc1ae74 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -18,8 +18,8 @@ import (
type RawTtyFormatter struct {
}
-// Attach to a container
-func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool) error {
+// Start (if required) and attach to a container
+func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool, startContainer bool) error {
ctx := context.Background()
resize := make(chan remotecommand.TerminalSize)
@@ -67,60 +67,12 @@ func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys
streams.AttachInput = false
}
- if sigProxy {
- ProxySignals(ctr)
- }
-
- return ctr.Attach(streams, detachKeys, resize)
-}
-
-// Start and attach to a container
-func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool) error {
- ctx := context.Background()
- resize := make(chan remotecommand.TerminalSize)
-
- haveTerminal := terminal.IsTerminal(int(os.Stdin.Fd()))
-
- // Check if we are attached to a terminal. If we are, generate resize
- // events, and set the terminal to raw mode
- if haveTerminal && ctr.Spec().Process.Terminal {
- logrus.Debugf("Handling terminal attach")
-
- subCtx, cancel := context.WithCancel(ctx)
- defer cancel()
-
- resizeTty(subCtx, resize)
-
- oldTermState, err := term.SaveState(os.Stdin.Fd())
- if err != nil {
- return errors.Wrapf(err, "unable to save terminal state")
+ if !startContainer {
+ if sigProxy {
+ ProxySignals(ctr)
}
- logrus.SetFormatter(&RawTtyFormatter{})
- term.SetRawTerminal(os.Stdin.Fd())
-
- defer restoreTerminal(oldTermState)
- }
-
- streams := new(libpod.AttachStreams)
- streams.OutputStream = stdout
- streams.ErrorStream = stderr
- streams.InputStream = stdin
- streams.AttachOutput = true
- streams.AttachError = true
- streams.AttachInput = true
-
- if stdout == nil {
- logrus.Debugf("Not attaching to stdout")
- streams.AttachOutput = false
- }
- if stderr == nil {
- logrus.Debugf("Not attaching to stderr")
- streams.AttachError = false
- }
- if stdin == nil {
- logrus.Debugf("Not attaching to stdin")
- streams.AttachInput = false
+ return ctr.Attach(streams, detachKeys, resize)
}
attachChan, err := ctr.StartAndAttach(getContext(), streams, detachKeys, resize)