From e480aedaeaed179db1a9a61c4dc2f568476f0507 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 14 Dec 2015 13:31:30 -0800 Subject: [PATCH] Add console support Signed-off-by: Michael Crosby --- linux/linux.go | 28 ++++++++++++++++------------ runtime/container.go | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/linux/linux.go b/linux/linux.go index d5f5c4e..a3a94b6 100644 --- a/linux/linux.go +++ b/linux/linux.go @@ -395,9 +395,21 @@ func (r *libcontainerRuntime) Create(id, bundlePath string) (runtime.Container, if err != nil { return nil, nil, err } - i, err := process.InitializeIO(int(spec.Process.User.UID)) - if err != nil { - return nil, nil, err + var rio runtime.IO + if spec.Process.Terminal { + console, err := process.NewConsole(int(spec.Process.User.UID)) + if err != nil { + return nil, nil, err + } + rio.Console = console + } else { + i, err := process.InitializeIO(int(spec.Process.User.UID)) + if err != nil { + return nil, nil, err + } + rio.Stdin = i.Stdin + rio.Stderr = i.Stderr + rio.Stdout = i.Stdout } c := &libcontainerContainer{ c: container, @@ -408,11 +420,7 @@ func (r *libcontainerRuntime) Create(id, bundlePath string) (runtime.Container, }, path: bundlePath, } - return c, &runtime.IO{ - Stdin: i.Stdin, - Stdout: i.Stdout, - Stderr: i.Stderr, - }, nil + return c, &rio, nil } func (r *libcontainerRuntime) StartProcess(ci runtime.Container, p specs.Process) (runtime.Process, *runtime.IO, error) { @@ -450,10 +458,6 @@ func (r *libcontainerRuntime) StartProcess(ci runtime.Container, p specs.Process // newProcess returns a new libcontainer Process with the arguments from the // spec and stdio from the current process. func (r *libcontainerRuntime) newProcess(p specs.Process) (*libcontainer.Process, error) { - // TODO: support terminals - if p.Terminal { - return nil, runtime.ErrTerminalsNotSupported - } return &libcontainer.Process{ Args: p.Args, Env: p.Env, diff --git a/runtime/container.go b/runtime/container.go index 7069f9d..b25b69b 100644 --- a/runtime/container.go +++ b/runtime/container.go @@ -26,10 +26,16 @@ type State struct { Status Status } +type Console interface { + io.ReadWriter + io.Closer +} + type IO struct { - Stdin io.WriteCloser - Stdout io.ReadCloser - Stderr io.ReadCloser + Stdin io.WriteCloser + Stdout io.ReadCloser + Stderr io.ReadCloser + Console Console } func (i *IO) Close() error { @@ -39,10 +45,15 @@ func (i *IO) Close() error { i.Stdout, i.Stderr, } { - if err := c.Close(); oerr == nil { - oerr = err + if c != nil { + if err := c.Close(); oerr == nil { + oerr = err + } } } + if i.Console != nil { + oerr = i.Console.Close() + } return oerr }