Skip to content

Commit 830c0d7

Browse files
committed
libcontainer/console_linux.go: Make SaneTerminal public
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 <[email protected]>
1 parent ea35825 commit 830c0d7

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

contrib/cmd/recvtty/recvtty.go

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"strings"
2626

27+
"github.com/opencontainers/runc/libcontainer"
2728
"github.com/opencontainers/runc/libcontainer/utils"
2829
"github.com/urfave/cli"
2930
)
@@ -100,6 +101,9 @@ func handleSingle(path string) error {
100101
if err != nil {
101102
return err
102103
}
104+
if err = libcontainer.SaneTerminal(master); err != nil {
105+
return err
106+
}
103107

104108
// Copy from our stdio to the master fd.
105109
quitChan := make(chan struct{})

libcontainer/console_linux.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ func newConsole() (Console, error) {
2121
if err != nil {
2222
return nil, err
2323
}
24-
if err := saneTerminal(master); err != nil {
25-
return nil, err
26-
}
2724
console, err := ptsname(master)
2825
if err != nil {
2926
return nil, err
@@ -133,12 +130,12 @@ func ptsname(f *os.File) (string, error) {
133130
return fmt.Sprintf("/dev/pts/%d", n), nil
134131
}
135132

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

libcontainer/integration/execin_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ func TestExecInTTY(t *testing.T) {
300300
err: err,
301301
}
302302
}
303+
libcontainer.SaneTerminal(f)
303304
dc <- &cdata{
304305
c: libcontainer.ConsoleFromFile(f),
305306
}

tty.go

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) error {
7474
if err != nil {
7575
return err
7676
}
77+
if err = libcontainer.SaneTerminal(f); err != nil {
78+
return err
79+
}
7780
console := libcontainer.ConsoleFromFile(f)
7881
go io.Copy(console, os.Stdin)
7982
t.wg.Add(1)

0 commit comments

Comments
 (0)