From 8d7635b1ac3eaea83fcf481994294eb137110e96 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 12 Apr 2018 12:26:51 -0400 Subject: Change attach to accept a struct containing streams Comparing Go interfaces, like io.Reader, to nil does not work. As such, we need to include a bool with each stream telling whether to attach to it. Signed-off-by: Matthew Heon Closes: #608 Approved by: baude --- cmd/podman/utils.go | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'cmd/podman/utils.go') diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go index 0238fc9c2..925674474 100644 --- a/cmd/podman/utils.go +++ b/cmd/podman/utils.go @@ -73,7 +73,7 @@ func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys // Check if we are attached to a terminal. If we are, generate resize // events, and set the terminal to raw mode - if haveTerminal { + if haveTerminal && ctr.Spec().Process.Terminal { logrus.Debugf("Handling terminal attach") resizeTty(resize) @@ -88,11 +88,32 @@ func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys defer term.RestoreTerminal(os.Stdin.Fd(), 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 + } + if sigProxy { ProxySignals(ctr) } - return ctr.Attach(stdout, stderr, stdin, detachKeys, resize) + return ctr.Attach(streams, detachKeys, resize) } // Start and attach to a container @@ -119,7 +140,28 @@ func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detac defer term.RestoreTerminal(os.Stdin.Fd(), oldTermState) } - attachChan, err := ctr.StartAndAttach(stdout, stderr, stdin, detachKeys, resize) + 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 + } + + attachChan, err := ctr.StartAndAttach(streams, detachKeys, resize) if err != nil { return err } -- cgit v1.2.3-54-g00ecf