Skip to content

Commit

Permalink
Merge pull request #827 from crosbymichael/update-console
Browse files Browse the repository at this point in the history
Update go-runc and console packages
  • Loading branch information
estesp authored May 9, 2017
2 parents d24f39e + 1494d8f commit 8ef7df5
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 25 deletions.
2 changes: 1 addition & 1 deletion containerd-shim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"syscall"

"github.com/containerd/containerd/osutils"
"github.com/crosbymichael/console"
"github.com/containerd/console"
)

func writeMessage(f *os.File, level string, err error) {
Expand Down
4 changes: 2 additions & 2 deletions containerd-shim/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

"github.com/containerd/containerd/osutils"
"github.com/containerd/containerd/specs"
"github.com/crosbymichael/console"
runc "github.com/crosbymichael/go-runc"
"github.com/containerd/console"
runc "github.com/containerd/go-runc"
)

var errRuntime = errors.New("shim: runtime execution error")
Expand Down
4 changes: 2 additions & 2 deletions containerd-shim/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/containerd/containerd/osutils"
"github.com/crosbymichael/console"
runc "github.com/crosbymichael/go-runc"
"github.com/containerd/console"
runc "github.com/containerd/go-runc"
"github.com/tonistiigi/fifo"
"golang.org/x/net/context"
)
Expand Down
2 changes: 1 addition & 1 deletion ctr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/containerd/containerd/api/grpc/types"
"github.com/containerd/containerd/specs"
"github.com/crosbymichael/console"
"github.com/containerd/console"
"github.com/golang/protobuf/ptypes"
"github.com/urfave/cli"
netcontext "golang.org/x/net/context"
Expand Down
4 changes: 2 additions & 2 deletions hack/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ clone git github.com/pkg/errors 839d9e913e063e28dfd0e6c7b7512793e0a48be9
clone git github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
clone git github.com/go-check/check a625211d932a2a643d0d17352095f03fb7774663 https://github.com/cpuguy83/check.git

clone git github.com/crosbymichael/console 8ea0f623ee22736eec36b4ec87664b1d82cf9d15
clone git github.com/crosbymichael/go-runc 980b32fc0fe2280022206962a536657010d9e072
clone git github.com/containerd/console a3863895279f5104533fd999c1babf80faffd98c
clone git github.com/containerd/go-runc 5fe4d8cb7fdc0fae5f5a7f4f1d65a565032401b2

# dependencies of docker/pkg/listeners
clone git github.com/docker/go-connections v0.2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# console

[![Build Status](https://travis-ci.org/crosbymichael/console.svg?branch=master)](https://travis-ci.org/crosbymichael/console)
[![Build Status](https://travis-ci.org/containerd/console.svg?branch=master)](https://travis-ci.org/containerd/console)

Golang package for dealing with consoles. Light on deps and a simple API.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Console interface {
ResizeFrom(Console) error
// SetRaw sets the console in raw mode
SetRaw() error
// DisableEcho disables echo on the console
DisableEcho() error
// Reset restores the console to its orignal state
Reset() error
// Size returns the window size of the console
Expand All @@ -28,12 +30,12 @@ type Console interface {

// WinSize specifies the window size of the console
type WinSize struct {
// Width of the console
Width uint16
// Height of the console
Height uint16
x uint16
y uint16
// Width of the console
Width uint16
x uint16
y uint16
}

// Current returns the current processes console
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build darwin freebsd linux

package console

// #include <termios.h>
Expand Down Expand Up @@ -34,8 +36,8 @@ func NewPty() (Console, string, error) {
}

type master struct {
f *os.File
termios *unix.Termios
f *os.File
original *unix.Termios
}

func (m *master) Read(b []byte) (int, error) {
Expand Down Expand Up @@ -67,23 +69,42 @@ func (m *master) ResizeFrom(c Console) error {
}

func (m *master) Reset() error {
if m.termios == nil {
if m.original == nil {
return nil
}
return tcset(m.f.Fd(), m.termios)
return tcset(m.f.Fd(), m.original)
}

func (m *master) getCurrent() (unix.Termios, error) {
var termios unix.Termios
if err := tcget(m.f.Fd(), &termios); err != nil {
return unix.Termios{}, err
}
if m.original == nil {
m.original = &termios
}
return termios, nil
}

func (m *master) SetRaw() error {
m.termios = &unix.Termios{}
if err := tcget(m.f.Fd(), m.termios); err != nil {
rawState, err := m.getCurrent()
if err != nil {
return err
}
rawState := *m.termios
C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&rawState)))
rawState.Oflag = rawState.Oflag | C.OPOST
return tcset(m.f.Fd(), &rawState)
}

func (m *master) DisableEcho() error {
rawState, err := m.getCurrent()
if err != nil {
return err
}
rawState.Lflag = rawState.Lflag &^ unix.ECHO
return tcset(m.f.Fd(), &rawState)
}

func (m *master) Size() (WinSize, error) {
var ws WinSize
if err := ioctl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ func (m *master) ResizeFrom(c Console) error {
return ErrNotImplemented
}

func (m *master) DisableEcho() error {
mode := m.inMode &^ winterm.ENABLE_ECHO_INPUT
mode |= winterm.ENABLE_PROCESSED_INPUT
mode |= winterm.ENABLE_LINE_INPUT

if err := winterm.SetConsoleMode(m.in, mode); err != nil {
return errors.Wrap(err, "unable to set console to disable echo")
}

return nil
}

func (m *master) Close() error {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !linux

package console

import (
Expand Down
51 changes: 51 additions & 0 deletions vendor/src/github.com/containerd/console/tc_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package console

import (
"fmt"
"os"
"unsafe"

"golang.org/x/sys/unix"
)

func tcget(fd uintptr, p *unix.Termios) error {
return ioctl(fd, unix.TIOCGETA, uintptr(unsafe.Pointer(p)))
}

func tcset(fd uintptr, p *unix.Termios) error {
return ioctl(fd, unix.TIOCSETA, uintptr(unsafe.Pointer(p)))
}

func ioctl(fd, flag, data uintptr) error {
if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, flag, data); err != 0 {
return err
}
return nil
}

// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
// unlockpt should be called before opening the slave side of a pty.
// This does not exist on FreeBSD, it does not allocate controlling terminals on open
func unlockpt(f *os.File) error {
return nil
}

// ptsname retrieves the name of the first available pts for the given master.
func ptsname(f *os.File) (string, error) {
var n int32
if err := ioctl(f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
return "", err
}
return fmt.Sprintf("/dev/pts/%d", n), nil
}

func saneTerminal(f *os.File) error {
// Go doesn't have a wrapper for any of the termios ioctls.
var termios unix.Termios
if err := tcget(f.Fd(), &termios); err != nil {
return err
}
// Set -onlcr so we don't have to deal with \r.
termios.Oflag &^= unix.ONLCR
return tcset(f.Fd(), &termios)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go-runc

[![Build Status](https://travis-ci.org/crosbymichael/go-runc.svg?branch=master)](https://travis-ci.org/crosbymichael/go-runc)
[![Build Status](https://travis-ci.org/containerd/go-runc.svg?branch=master)](https://travis-ci.org/containerd/go-runc)


This is a package for consuming the [runc](https://github.com/opencontainers/runc) binary in your Go applications.
Expand All @@ -11,7 +11,7 @@ or greater.

## Docs

Docs can be found at [godoc.org](https://godoc.org/github.com/crosbymichael/go-runc).
Docs can be found at [godoc.org](https://godoc.org/github.com/containerd/go-runc).


## LICENSE - MIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"path/filepath"

"github.com/crosbymichael/console"
"github.com/containerd/console"
"github.com/opencontainers/runc/libcontainer/utils"
)

Expand Down

0 comments on commit 8ef7df5

Please sign in to comment.