Update go-runc and console packages

This fixes an issue in the console package with width and height swapped
when making the ioctls.

It also updates the packages to point to their new location under the
containerd org.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-05-09 15:52:54 -07:00
parent d24f39e203
commit 1494d8f3b8
24 changed files with 109 additions and 25 deletions

View File

@ -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) {

View File

@ -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")

View File

@ -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"
)

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,5 @@
// +build darwin freebsd linux
package console
// #include <termios.h>
@ -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) {
@ -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(

View File

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

View File

@ -1,5 +1,3 @@
// +build !linux
package console
import (

View File

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

View File

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

View File

@ -9,7 +9,7 @@ import (
"os"
"path/filepath"
"github.com/crosbymichael/console"
"github.com/containerd/console"
"github.com/opencontainers/runc/libcontainer/utils"
)