Skip to content

Commit ddf4486

Browse files
committed
Fix console syscalls
Signed-off-by: Christy Perez <[email protected]>
1 parent 653207b commit ddf4486

File tree

191 files changed

+121943
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+121943
-15
lines changed

libcontainer/console_linux.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package libcontainer
33
import (
44
"fmt"
55
"os"
6-
"syscall"
76
"unsafe"
7+
8+
"golang.org/x/sys/unix"
89
)
910

1011
func ConsoleFromFile(f *os.File) Console {
@@ -16,7 +17,7 @@ func ConsoleFromFile(f *os.File) Console {
1617
// newConsole returns an initialized console that can be used within a container by copying bytes
1718
// from the master side to the slave that is attached as the tty for the container's init process.
1819
func newConsole() (Console, error) {
19-
master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
20+
master, err := os.OpenFile("/dev/ptmx", unix.O_RDWR|unix.O_NOCTTY|unix.O_CLOEXEC, 0)
2021
if err != nil {
2122
return nil, err
2223
}
@@ -68,28 +69,28 @@ func (c *linuxConsole) Close() error {
6869
// mount initializes the console inside the rootfs mounting with the specified mount label
6970
// and applying the correct ownership of the console.
7071
func (c *linuxConsole) mount() error {
71-
oldMask := syscall.Umask(0000)
72-
defer syscall.Umask(oldMask)
72+
oldMask := unix.Umask(0000)
73+
defer unix.Umask(oldMask)
7374
f, err := os.Create("/dev/console")
7475
if err != nil && !os.IsExist(err) {
7576
return err
7677
}
7778
if f != nil {
7879
f.Close()
7980
}
80-
return syscall.Mount(c.slavePath, "/dev/console", "bind", syscall.MS_BIND, "")
81+
return unix.Mount(c.slavePath, "/dev/console", "bind", unix.MS_BIND, "")
8182
}
8283

8384
// dupStdio opens the slavePath for the console and dups the fds to the current
8485
// processes stdio, fd 0,1,2.
8586
func (c *linuxConsole) dupStdio() error {
86-
slave, err := c.open(syscall.O_RDWR)
87+
slave, err := c.open(unix.O_RDWR)
8788
if err != nil {
8889
return err
8990
}
9091
fd := int(slave.Fd())
9192
for _, i := range []int{0, 1, 2} {
92-
if err := syscall.Dup3(fd, i, 0); err != nil {
93+
if err := unix.Dup3(fd, i, 0); err != nil {
9394
return err
9495
}
9596
}
@@ -98,7 +99,7 @@ func (c *linuxConsole) dupStdio() error {
9899

99100
// open is a clone of os.OpenFile without the O_CLOEXEC used to open the pty slave.
100101
func (c *linuxConsole) open(flag int) (*os.File, error) {
101-
r, e := syscall.Open(c.slavePath, flag, 0)
102+
r, e := unix.Open(c.slavePath, flag, 0)
102103
if e != nil {
103104
return nil, &os.PathError{
104105
Op: "open",
@@ -110,7 +111,7 @@ func (c *linuxConsole) open(flag int) (*os.File, error) {
110111
}
111112

112113
func ioctl(fd uintptr, flag, data uintptr) error {
113-
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, flag, data); err != 0 {
114+
if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, flag, data); err != 0 {
114115
return err
115116
}
116117
return nil
@@ -120,13 +121,13 @@ func ioctl(fd uintptr, flag, data uintptr) error {
120121
// unlockpt should be called before opening the slave side of a pty.
121122
func unlockpt(f *os.File) error {
122123
var u int32
123-
return ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
124+
return ioctl(f.Fd(), unix.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
124125
}
125126

126127
// ptsname retrieves the name of the first available pts for the given master.
127128
func ptsname(f *os.File) (string, error) {
128129
var n int32
129-
if err := ioctl(f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
130+
if err := ioctl(f.Fd(), unix.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
130131
return "", err
131132
}
132133
return fmt.Sprintf("/dev/pts/%d", n), nil
@@ -139,16 +140,16 @@ func ptsname(f *os.File) (string, error) {
139140
// also relay that funky line discipline.
140141
func saneTerminal(terminal *os.File) error {
141142
// Go doesn't have a wrapper for any of the termios ioctls.
142-
var termios syscall.Termios
143+
var termios unix.Termios
143144

144-
if err := ioctl(terminal.Fd(), syscall.TCGETS, uintptr(unsafe.Pointer(&termios))); err != nil {
145+
if err := ioctl(terminal.Fd(), unix.TCGETS, uintptr(unsafe.Pointer(&termios))); err != nil {
145146
return fmt.Errorf("ioctl(tty, tcgets): %s", err.Error())
146147
}
147148

148149
// Set -onlcr so we don't have to deal with \r.
149-
termios.Oflag &^= syscall.ONLCR
150+
termios.Oflag &^= unix.ONLCR
150151

151-
if err := ioctl(terminal.Fd(), syscall.TCSETS, uintptr(unsafe.Pointer(&termios))); err != nil {
152+
if err := ioctl(terminal.Fd(), unix.TCSETS, uintptr(unsafe.Pointer(&termios))); err != nil {
152153
return fmt.Errorf("ioctl(tty, tcsets): %s", err.Error())
153154
}
154155

vendor.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20efbcb237f3ce0
1111
github.com/syndtr/gocapability/capability e7cb7fa329f456b3855136a2642b197bad7366ba
1212
github.com/urfave/cli d53eb991652b1d438abdd34ce4bfa3ef1539108e
1313
github.com/vishvananda/netlink 1e2e08e8a2dcdacaae3f14ac44c5cfa31361f270
14+
golang.org/x/sys 99f16d856c9836c42d24e7ab64ea72916925fa97

vendor/golang.org/x/sys/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/PATENTS

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/README

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/asm_darwin_386.s

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/asm_darwin_amd64.s

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/asm_darwin_arm.s

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/asm_darwin_arm64.s

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/asm_freebsd_386.s

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)