Skip to content

Commit

Permalink
libcontainer/console_linux.go: Make SaneTerminal public
Browse files Browse the repository at this point in the history
And use it only in local tooling that is forwarding the pseudoterminal
master.  That way runC no longer has an opinion on the onlcr setting
for folks who are creating a terminal and detaching.  They'll use
--console-socket and can setup the pseudoterminal however they like
without runC having an opinion.  With this commit, the only cases
where runC still has applies SaneTerminal is when *it* is the process
consuming the master descriptor.

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Jun 8, 2017
1 parent ea35825 commit 830c0d7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions contrib/cmd/recvtty/recvtty.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"strings"

"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/utils"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -100,6 +101,9 @@ func handleSingle(path string) error {
if err != nil {
return err
}
if err = libcontainer.SaneTerminal(master); err != nil {
return err
}

// Copy from our stdio to the master fd.
quitChan := make(chan struct{})
Expand Down
7 changes: 2 additions & 5 deletions libcontainer/console_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ func newConsole() (Console, error) {
if err != nil {
return nil, err
}
if err := saneTerminal(master); err != nil {
return nil, err
}
console, err := ptsname(master)
if err != nil {
return nil, err
Expand Down Expand Up @@ -133,12 +130,12 @@ func ptsname(f *os.File) (string, error) {
return fmt.Sprintf("/dev/pts/%d", n), nil
}

// saneTerminal sets the necessary tty_ioctl(4)s to ensure that a pty pair
// SaneTerminal sets the necessary tty_ioctl(4)s to ensure that a pty pair
// created by us acts normally. In particular, a not-very-well-known default of
// Linux unix98 ptys is that they have +onlcr by default. While this isn't a
// problem for terminal emulators, because we relay data from the terminal we
// also relay that funky line discipline.
func saneTerminal(terminal *os.File) error {
func SaneTerminal(terminal *os.File) error {
// Go doesn't have a wrapper for any of the termios ioctls.
var termios unix.Termios

Expand Down
1 change: 1 addition & 0 deletions libcontainer/integration/execin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func TestExecInTTY(t *testing.T) {
err: err,
}
}
libcontainer.SaneTerminal(f)
dc <- &cdata{
c: libcontainer.ConsoleFromFile(f),
}
Expand Down
3 changes: 3 additions & 0 deletions tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) error {
if err != nil {
return err
}
if err = libcontainer.SaneTerminal(f); err != nil {
return err
}
console := libcontainer.ConsoleFromFile(f)
go io.Copy(console, os.Stdin)
t.wg.Add(1)
Expand Down

0 comments on commit 830c0d7

Please sign in to comment.