Add console support

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2015-12-14 13:31:30 -08:00
parent 25973db0c9
commit e480aedaea
2 changed files with 32 additions and 17 deletions

View file

@ -395,9 +395,21 @@ func (r *libcontainerRuntime) Create(id, bundlePath string) (runtime.Container,
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
i, err := process.InitializeIO(int(spec.Process.User.UID)) var rio runtime.IO
if err != nil { if spec.Process.Terminal {
return nil, nil, err 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 := &libcontainerContainer{
c: container, c: container,
@ -408,11 +420,7 @@ func (r *libcontainerRuntime) Create(id, bundlePath string) (runtime.Container,
}, },
path: bundlePath, path: bundlePath,
} }
return c, &runtime.IO{ return c, &rio, nil
Stdin: i.Stdin,
Stdout: i.Stdout,
Stderr: i.Stderr,
}, nil
} }
func (r *libcontainerRuntime) StartProcess(ci runtime.Container, p specs.Process) (runtime.Process, *runtime.IO, error) { 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 // newProcess returns a new libcontainer Process with the arguments from the
// spec and stdio from the current process. // spec and stdio from the current process.
func (r *libcontainerRuntime) newProcess(p specs.Process) (*libcontainer.Process, error) { func (r *libcontainerRuntime) newProcess(p specs.Process) (*libcontainer.Process, error) {
// TODO: support terminals
if p.Terminal {
return nil, runtime.ErrTerminalsNotSupported
}
return &libcontainer.Process{ return &libcontainer.Process{
Args: p.Args, Args: p.Args,
Env: p.Env, Env: p.Env,

View file

@ -26,10 +26,16 @@ type State struct {
Status Status Status Status
} }
type Console interface {
io.ReadWriter
io.Closer
}
type IO struct { type IO struct {
Stdin io.WriteCloser Stdin io.WriteCloser
Stdout io.ReadCloser Stdout io.ReadCloser
Stderr io.ReadCloser Stderr io.ReadCloser
Console Console
} }
func (i *IO) Close() error { func (i *IO) Close() error {
@ -39,10 +45,15 @@ func (i *IO) Close() error {
i.Stdout, i.Stdout,
i.Stderr, i.Stderr,
} { } {
if err := c.Close(); oerr == nil { if c != nil {
oerr = err if err := c.Close(); oerr == nil {
oerr = err
}
} }
} }
if i.Console != nil {
oerr = i.Console.Close()
}
return oerr return oerr
} }