Skip to content

Commit a0159fd

Browse files
Merge pull request opencontainers#1504 from tklauser/more-unix-funcs
Use Prctl() and ioctl wrapper functions from x/sys/unix
2 parents 5c73abb + 078e903 commit a0159fd

27 files changed

+268
-185
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/seccomp/seccomp_linux.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ var (
2020
actKill = libseccomp.ActKill
2121
actTrace = libseccomp.ActTrace.SetReturnCode(int16(unix.EPERM))
2222
actErrno = libseccomp.ActErrno.SetReturnCode(int16(unix.EPERM))
23-
24-
// SeccompModeFilter refers to the syscall argument SECCOMP_MODE_FILTER.
25-
SeccompModeFilter = uintptr(2)
2623
)
2724

2825
// Filters given syscalls in a container, preventing them from being used
@@ -85,9 +82,9 @@ func IsEnabled() bool {
8582
s, err := parseStatusFile("/proc/self/status")
8683
if err != nil {
8784
// Check if Seccomp is supported, via CONFIG_SECCOMP.
88-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_GET_SECCOMP, 0, 0); err != unix.EINVAL {
85+
if err := unix.Prctl(unix.PR_GET_SECCOMP, 0, 0, 0, 0); err != unix.EINVAL {
8986
// Make sure the kernel has CONFIG_SECCOMP_FILTER.
90-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_SECCOMP, SeccompModeFilter, 0); err != unix.EINVAL {
87+
if err := unix.Prctl(unix.PR_SET_SECCOMP, unix.SECCOMP_MODE_FILTER, 0, 0, 0); err != unix.EINVAL {
9188
return true
9289
}
9390
}

libcontainer/system/linux.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,39 +64,38 @@ func Prlimit(pid, resource int, limit unix.Rlimit) error {
6464
}
6565

6666
func SetParentDeathSignal(sig uintptr) error {
67-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_PDEATHSIG, sig, 0); err != 0 {
67+
if err := unix.Prctl(unix.PR_SET_PDEATHSIG, sig, 0, 0, 0); err != nil {
6868
return err
6969
}
7070
return nil
7171
}
7272

7373
func GetParentDeathSignal() (ParentDeathSignal, error) {
7474
var sig int
75-
_, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0)
76-
if err != 0 {
75+
if err := unix.Prctl(unix.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0, 0, 0); err != nil {
7776
return -1, err
7877
}
7978
return ParentDeathSignal(sig), nil
8079
}
8180

8281
func SetKeepCaps() error {
83-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_KEEPCAPS, 1, 0); err != 0 {
82+
if err := unix.Prctl(unix.PR_SET_KEEPCAPS, 1, 0, 0, 0); err != nil {
8483
return err
8584
}
8685

8786
return nil
8887
}
8988

9089
func ClearKeepCaps() error {
91-
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_KEEPCAPS, 0, 0); err != 0 {
90+
if err := unix.Prctl(unix.PR_SET_KEEPCAPS, 0, 0, 0, 0); err != nil {
9291
return err
9392
}
9493

9594
return nil
9695
}
9796

9897
func Setctty() error {
99-
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 {
10099
return err
101100
}
102101
return nil

vendor.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ github.com/golang/protobuf 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8
1818
github.com/docker/docker 0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d
1919
github.com/docker/go-units v0.2.0
2020
github.com/urfave/cli d53eb991652b1d438abdd34ce4bfa3ef1539108e
21-
golang.org/x/sys fb4cac33e3196ff7f507ab9b2d2a44b0142f5b5a https://github.com/golang/sys
21+
golang.org/x/sys 0e0164865330d5cf1c00247be08330bf96e2f87c https://github.com/golang/sys

vendor/golang.org/x/sys/unix/syscall_linux.go

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/unix/zerrors_linux_386.go

Lines changed: 6 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/zerrors_linux_amd64.go

Lines changed: 6 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/zerrors_linux_arm.go

Lines changed: 6 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/zerrors_linux_arm64.go

Lines changed: 6 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/zerrors_linux_mips.go

Lines changed: 6 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/zerrors_linux_mips64.go

Lines changed: 6 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/zerrors_linux_mips64le.go

Lines changed: 6 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/zerrors_linux_mipsle.go

Lines changed: 6 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)