Merge pull request #428 from crosbymichael/console
Export console New func
This commit is contained in:
commit
39b80c46bc
|
@ -6,8 +6,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newConsole returns an initalized console that can be used within a container by copying bytes
|
// NewConsole returns an initalized console that can be used within a container by copying bytes
|
||||||
// from the master side to the slave that is attached as the tty for the container's init process.
|
// from the master side to the slave that is attached as the tty for the container's init process.
|
||||||
func newConsole(uid, gid int) (Console, error) {
|
func NewConsole(uid, gid int) (Console, error) {
|
||||||
return nil, errors.New("libcontainer console is not supported on FreeBSD")
|
return nil, errors.New("libcontainer console is not supported on FreeBSD")
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"github.com/opencontainers/runc/libcontainer/label"
|
"github.com/opencontainers/runc/libcontainer/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newConsole returns an initalized console that can be used within a container by copying bytes
|
// NewConsole returns an initalized console that can be used within a container by copying bytes
|
||||||
// from the master side to the slave that is attached as the tty for the container's init process.
|
// from the master side to the slave that is attached as the tty for the container's init process.
|
||||||
func newConsole(uid, gid int) (Console, error) {
|
func NewConsole(uid, gid int) (Console, error) {
|
||||||
master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
|
master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package libcontainer
|
package libcontainer
|
||||||
|
|
||||||
// newConsole returns an initalized console that can be used within a container
|
// NewConsole returns an initalized console that can be used within a container
|
||||||
func newConsole(uid, gid int) (Console, error) {
|
func NewConsole(uid, gid int) (Console, error) {
|
||||||
return &windowsConsole{}, nil
|
return &windowsConsole{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ const (
|
||||||
|
|
||||||
// Common errors
|
// Common errors
|
||||||
ConfigInvalid
|
ConfigInvalid
|
||||||
|
ConsoleExists
|
||||||
SystemError
|
SystemError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,6 +44,8 @@ func (c ErrorCode) String() string {
|
||||||
return "Container is not stopped"
|
return "Container is not stopped"
|
||||||
case ContainerNotRunning:
|
case ContainerNotRunning:
|
||||||
return "Container is not running"
|
return "Container is not running"
|
||||||
|
case ConsoleExists:
|
||||||
|
return "Console exist for process"
|
||||||
default:
|
default:
|
||||||
return "Unknown error"
|
return "Unknown error"
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,10 +80,19 @@ func (p Process) Signal(sig os.Signal) error {
|
||||||
|
|
||||||
// NewConsole creates new console for process and returns it
|
// NewConsole creates new console for process and returns it
|
||||||
func (p *Process) NewConsole(rootuid int) (Console, error) {
|
func (p *Process) NewConsole(rootuid int) (Console, error) {
|
||||||
console, err := newConsole(rootuid, rootuid)
|
console, err := NewConsole(rootuid, rootuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.consolePath = console.Path()
|
p.consolePath = console.Path()
|
||||||
return console, nil
|
return console, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConsoleFromPath sets the process's console with the path provided
|
||||||
|
func (p *Process) ConsoleFromPath(path string) error {
|
||||||
|
if p.consolePath != "" {
|
||||||
|
return newGenericError(fmt.Errorf("console path already exists for process"), ConsoleExists)
|
||||||
|
}
|
||||||
|
p.consolePath = path
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue