Skip to content

Commit

Permalink
Merge pull request opencontainers#428 from crosbymichael/console
Browse files Browse the repository at this point in the history
Export console New func
  • Loading branch information
LK4D4 committed Dec 9, 2015
2 parents 3317785 + 9c9aac5 commit 39b80c4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libcontainer/console_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"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.
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")
}
4 changes: 2 additions & 2 deletions libcontainer/console_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"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.
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)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/console_windows.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package libcontainer

// newConsole returns an initalized console that can be used within a container
func newConsole(uid, gid int) (Console, error) {
// NewConsole returns an initalized console that can be used within a container
func NewConsole(uid, gid int) (Console, error) {
return &windowsConsole{}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions libcontainer/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (

// Common errors
ConfigInvalid
ConsoleExists
SystemError
)

Expand All @@ -43,6 +44,8 @@ func (c ErrorCode) String() string {
return "Container is not stopped"
case ContainerNotRunning:
return "Container is not running"
case ConsoleExists:
return "Console exist for process"
default:
return "Unknown error"
}
Expand Down
11 changes: 10 additions & 1 deletion libcontainer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,19 @@ func (p Process) Signal(sig os.Signal) error {

// NewConsole creates new console for process and returns it
func (p *Process) NewConsole(rootuid int) (Console, error) {
console, err := newConsole(rootuid, rootuid)
console, err := NewConsole(rootuid, rootuid)
if err != nil {
return nil, err
}
p.consolePath = console.Path()
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
}

0 comments on commit 39b80c4

Please sign in to comment.