summaryrefslogtreecommitdiff
path: root/cmd/podman/run.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-04-11 13:09:41 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-13 18:43:44 +0000
commit5e03cec7ec83f8ff8b31a89a6180dda203b04d9c (patch)
treeb32484a6c5d15f430fca12f07db974e354636ccc /cmd/podman/run.go
parentb8394600d855a88b38f01feeadf5a63e703183cd (diff)
downloadpodman-5e03cec7ec83f8ff8b31a89a6180dda203b04d9c.tar.gz
podman-5e03cec7ec83f8ff8b31a89a6180dda203b04d9c.tar.bz2
podman-5e03cec7ec83f8ff8b31a89a6180dda203b04d9c.zip
Changes to attach to enable per-stream attaching
This allows us to attach to attach to just stdout or stderr or stdin, or any combination of these. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #608 Approved by: baude
Diffstat (limited to 'cmd/podman/run.go')
-rw-r--r--cmd/podman/run.go39
1 files changed, 36 insertions, 3 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 4966316c5..b8d6e0968 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -144,9 +144,42 @@ func runCmd(c *cli.Context) error {
return nil
}
- // TODO: that "false" should probably be linked to -i
- // Handle this when we split streams to allow attaching just stdin/out/err
- attachChan, err := ctr.StartAndAttach(false, c.String("detach-keys"))
+ outputStream := os.Stdout
+ errorStream := os.Stderr
+ inputStream := os.Stdin
+
+ // If -i is not set, clear stdin
+ if !c.Bool("interactive") {
+ inputStream = nil
+ }
+
+ // If attach is set, clear stdin/stdout/stderr and only attach requested
+ if c.IsSet("attach") {
+ outputStream = nil
+ errorStream = nil
+ inputStream = nil
+
+ attachTo := c.StringSlice("attach")
+ for _, stream := range attachTo {
+ switch strings.ToLower(stream) {
+ case "stdout":
+ outputStream = os.Stdout
+ case "stderr":
+ errorStream = os.Stderr
+ case "stdin":
+ inputStream = os.Stdin
+ default:
+ return errors.Wrapf(libpod.ErrInvalidArg, "invalid stream %q for --attach - must be one of stdin, stdout, or stderr", stream)
+ }
+ }
+
+ // If --interactive is set, restore stdin
+ if c.Bool("interactive") {
+ inputStream = os.Stdin
+ }
+ }
+
+ attachChan, err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"))
if err != nil {
// This means the command did not exist
exitCode = 127