From a60487b782d7f0e6e51756bf3e04dd63a1d35ee0 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Thu, 12 Jan 2017 11:37:03 -0800 Subject: [PATCH] ctr: set raw mode when using --tty Signed-off-by: Kenfe-Mickael Laventure --- cmd/ctr/run.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/ctr/run.go b/cmd/ctr/run.go index d6b4b30..8b8b7aa 100644 --- a/cmd/ctr/run.go +++ b/cmd/ctr/run.go @@ -10,6 +10,7 @@ import ( "github.com/docker/containerd/api/execution" execEvents "github.com/docker/containerd/execution" + "github.com/docker/docker/pkg/term" "github.com/nats-io/go-nats" "github.com/urfave/cli" ) @@ -98,6 +99,21 @@ var runCommand = cli.Command{ Stderr: filepath.Join(tmpDir, "stderr"), } + var oldState *term.State + restoreTerm := func() { + if oldState != nil { + term.RestoreTerminal(os.Stdin.Fd(), oldState) + } + } + + if crOpts.Console { + oldState, err = term.SetRawTerminal(os.Stdin.Fd()) + if err != nil { + return err + } + defer restoreTerm() + } + fwg, err := prepareStdio(crOpts.Stdin, crOpts.Stdout, crOpts.Stderr, crOpts.Console) if err != nil { return err @@ -143,6 +159,7 @@ var runCommand = cli.Command{ // Ensure we read all io fwg.Wait() + restoreTerm() os.Exit(int(ec)) return nil