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 {
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,

View File

@ -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
}