Skip to content

Commit 078e903

Browse files
committed
libcontainer: use ioctl wrappers from x/sys/unix
Use IoctlGetInt and IoctlGetTermios/IoctlSetTermios instead of manually reimplementing them. Because of unlockpt, the ioctl wrapper is still needed as it needs to pass a pointer to a value, which is not supported by any ioctl function in x/sys/unix yet. Signed-off-by: Tobias Klauser <[email protected]>
1 parent a380fae commit 078e903

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

libcontainer/console_linux.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ func unlockpt(f *os.File) error {
123123

124124
// ptsname retrieves the name of the first available pts for the given master.
125125
func ptsname(f *os.File) (string, error) {
126-
var n int32
127-
if err := ioctl(f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
126+
n, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCGPTN)
127+
if err != nil {
128128
return "", err
129129
}
130130
return fmt.Sprintf("/dev/pts/%d", n), nil
@@ -136,17 +136,15 @@ func ptsname(f *os.File) (string, error) {
136136
// problem for terminal emulators, because we relay data from the terminal we
137137
// also relay that funky line discipline.
138138
func SaneTerminal(terminal *os.File) error {
139-
// Go doesn't have a wrapper for any of the termios ioctls.
140-
var termios unix.Termios
141-
142-
if err := ioctl(terminal.Fd(), unix.TCGETS, uintptr(unsafe.Pointer(&termios))); err != nil {
139+
termios, err := unix.IoctlGetTermios(int(terminal.Fd()), unix.TCGETS)
140+
if err != nil {
143141
return fmt.Errorf("ioctl(tty, tcgets): %s", err.Error())
144142
}
145143

146144
// Set -onlcr so we don't have to deal with \r.
147145
termios.Oflag &^= unix.ONLCR
148146

149-
if err := ioctl(terminal.Fd(), unix.TCSETS, uintptr(unsafe.Pointer(&termios))); err != nil {
147+
if err := unix.IoctlSetTermios(int(terminal.Fd()), unix.TCSETS, termios); err != nil {
150148
return fmt.Errorf("ioctl(tty, tcsets): %s", err.Error())
151149
}
152150

libcontainer/system/linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func ClearKeepCaps() error {
9595
}
9696

9797
func Setctty() error {
98-
if _, _, err := unix.RawSyscall(unix.SYS_IOCTL, 0, uintptr(unix.TIOCSCTTY), 0); err != 0 {
98+
if err := unix.IoctlSetInt(0, unix.TIOCSCTTY, 0); err != nil {
9999
return err
100100
}
101101
return nil

0 commit comments

Comments
 (0)