Skip to content

Commit cc031d8

Browse files
authored
Merge pull request #1442 from clnperez/libcontainer-sys-unix
Move libcontainer to x/sys/unix
2 parents 4dce383 + 417999e commit cc031d8

File tree

14 files changed

+108
-136
lines changed

14 files changed

+108
-136
lines changed

libcontainer/cgroups/fs/memory.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import (
1010
"path/filepath"
1111
"strconv"
1212
"strings"
13-
"syscall"
13+
"syscall" // only for Errno
1414

1515
"github.com/opencontainers/runc/libcontainer/cgroups"
1616
"github.com/opencontainers/runc/libcontainer/configs"
17+
18+
"golang.org/x/sys/unix"
1719
)
1820

1921
const (
@@ -93,7 +95,7 @@ func setKernelMemory(path string, kernelMemoryLimit uint64) error {
9395
// once tasks have been attached to the cgroup
9496
if pathErr, ok := err.(*os.PathError); ok {
9597
if errNo, ok := pathErr.Err.(syscall.Errno); ok {
96-
if errNo == syscall.EBUSY {
98+
if errNo == unix.EBUSY {
9799
return fmt.Errorf("failed to set %s, because either tasks have already joined this cgroup or it has children", cgroupKernelMemoryLimit)
98100
}
99101
}

libcontainer/configs/namespaces_syscall.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
package configs
44

5-
import "syscall"
5+
import "golang.org/x/sys/unix"
66

77
func (n *Namespace) Syscall() int {
88
return namespaceInfo[n.Type]
99
}
1010

1111
var namespaceInfo = map[NamespaceType]int{
12-
NEWNET: syscall.CLONE_NEWNET,
13-
NEWNS: syscall.CLONE_NEWNS,
14-
NEWUSER: syscall.CLONE_NEWUSER,
15-
NEWIPC: syscall.CLONE_NEWIPC,
16-
NEWUTS: syscall.CLONE_NEWUTS,
17-
NEWPID: syscall.CLONE_NEWPID,
12+
NEWNET: unix.CLONE_NEWNET,
13+
NEWNS: unix.CLONE_NEWNS,
14+
NEWUSER: unix.CLONE_NEWUSER,
15+
NEWIPC: unix.CLONE_NEWIPC,
16+
NEWUTS: unix.CLONE_NEWUTS,
17+
NEWPID: unix.CLONE_NEWPID,
1818
}
1919

2020
// CloneFlags parses the container's Namespaces options to set the correct

libcontainer/devices/devices_linux.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"io/ioutil"
77
"os"
88
"path/filepath"
9-
"syscall"
9+
"syscall" //only for Stat_t
1010

1111
"github.com/opencontainers/runc/libcontainer/configs"
12+
13+
"golang.org/x/sys/unix"
1214
)
1315

1416
var (
@@ -36,10 +38,10 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) {
3638
case mode&os.ModeDevice == 0:
3739
return nil, ErrNotADevice
3840
case mode&os.ModeCharDevice != 0:
39-
fileModePermissionBits |= syscall.S_IFCHR
41+
fileModePermissionBits |= unix.S_IFCHR
4042
devType = 'c'
4143
default:
42-
fileModePermissionBits |= syscall.S_IFBLK
44+
fileModePermissionBits |= unix.S_IFBLK
4345
devType = 'b'
4446
}
4547
stat_t, ok := fileInfo.Sys().(*syscall.Stat_t)

libcontainer/specconv/spec_linux.go

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import (
99
"os"
1010
"path/filepath"
1111
"strings"
12-
"syscall"
1312
"time"
1413

1514
"github.com/opencontainers/runc/libcontainer/configs"
1615
"github.com/opencontainers/runc/libcontainer/seccomp"
1716
libcontainerUtils "github.com/opencontainers/runc/libcontainer/utils"
1817
"github.com/opencontainers/runtime-spec/specs-go"
18+
19+
"golang.org/x/sys/unix"
1920
)
2021

2122
const wildcard = -1
@@ -30,13 +31,13 @@ var namespaceMapping = map[specs.LinuxNamespaceType]configs.NamespaceType{
3031
}
3132

3233
var mountPropagationMapping = map[string]int{
33-
"rprivate": syscall.MS_PRIVATE | syscall.MS_REC,
34-
"private": syscall.MS_PRIVATE,
35-
"rslave": syscall.MS_SLAVE | syscall.MS_REC,
36-
"slave": syscall.MS_SLAVE,
37-
"rshared": syscall.MS_SHARED | syscall.MS_REC,
38-
"shared": syscall.MS_SHARED,
39-
"": syscall.MS_PRIVATE | syscall.MS_REC,
34+
"rprivate": unix.MS_PRIVATE | unix.MS_REC,
35+
"private": unix.MS_PRIVATE,
36+
"rslave": unix.MS_SLAVE | unix.MS_REC,
37+
"slave": unix.MS_SLAVE,
38+
"rshared": unix.MS_SHARED | unix.MS_REC,
39+
"shared": unix.MS_SHARED,
40+
"": unix.MS_PRIVATE | unix.MS_REC,
4041
}
4142

4243
var allowedDevices = []*configs.Device{
@@ -638,41 +639,41 @@ func parseMountOptions(options []string) (int, []int, string, int) {
638639
clear bool
639640
flag int
640641
}{
641-
"async": {true, syscall.MS_SYNCHRONOUS},
642-
"atime": {true, syscall.MS_NOATIME},
643-
"bind": {false, syscall.MS_BIND},
642+
"async": {true, unix.MS_SYNCHRONOUS},
643+
"atime": {true, unix.MS_NOATIME},
644+
"bind": {false, unix.MS_BIND},
644645
"defaults": {false, 0},
645-
"dev": {true, syscall.MS_NODEV},
646-
"diratime": {true, syscall.MS_NODIRATIME},
647-
"dirsync": {false, syscall.MS_DIRSYNC},
648-
"exec": {true, syscall.MS_NOEXEC},
649-
"mand": {false, syscall.MS_MANDLOCK},
650-
"noatime": {false, syscall.MS_NOATIME},
651-
"nodev": {false, syscall.MS_NODEV},
652-
"nodiratime": {false, syscall.MS_NODIRATIME},
653-
"noexec": {false, syscall.MS_NOEXEC},
654-
"nomand": {true, syscall.MS_MANDLOCK},
655-
"norelatime": {true, syscall.MS_RELATIME},
656-
"nostrictatime": {true, syscall.MS_STRICTATIME},
657-
"nosuid": {false, syscall.MS_NOSUID},
658-
"rbind": {false, syscall.MS_BIND | syscall.MS_REC},
659-
"relatime": {false, syscall.MS_RELATIME},
660-
"remount": {false, syscall.MS_REMOUNT},
661-
"ro": {false, syscall.MS_RDONLY},
662-
"rw": {true, syscall.MS_RDONLY},
663-
"strictatime": {false, syscall.MS_STRICTATIME},
664-
"suid": {true, syscall.MS_NOSUID},
665-
"sync": {false, syscall.MS_SYNCHRONOUS},
646+
"dev": {true, unix.MS_NODEV},
647+
"diratime": {true, unix.MS_NODIRATIME},
648+
"dirsync": {false, unix.MS_DIRSYNC},
649+
"exec": {true, unix.MS_NOEXEC},
650+
"mand": {false, unix.MS_MANDLOCK},
651+
"noatime": {false, unix.MS_NOATIME},
652+
"nodev": {false, unix.MS_NODEV},
653+
"nodiratime": {false, unix.MS_NODIRATIME},
654+
"noexec": {false, unix.MS_NOEXEC},
655+
"nomand": {true, unix.MS_MANDLOCK},
656+
"norelatime": {true, unix.MS_RELATIME},
657+
"nostrictatime": {true, unix.MS_STRICTATIME},
658+
"nosuid": {false, unix.MS_NOSUID},
659+
"rbind": {false, unix.MS_BIND | unix.MS_REC},
660+
"relatime": {false, unix.MS_RELATIME},
661+
"remount": {false, unix.MS_REMOUNT},
662+
"ro": {false, unix.MS_RDONLY},
663+
"rw": {true, unix.MS_RDONLY},
664+
"strictatime": {false, unix.MS_STRICTATIME},
665+
"suid": {true, unix.MS_NOSUID},
666+
"sync": {false, unix.MS_SYNCHRONOUS},
666667
}
667668
propagationFlags := map[string]int{
668-
"private": syscall.MS_PRIVATE,
669-
"shared": syscall.MS_SHARED,
670-
"slave": syscall.MS_SLAVE,
671-
"unbindable": syscall.MS_UNBINDABLE,
672-
"rprivate": syscall.MS_PRIVATE | syscall.MS_REC,
673-
"rshared": syscall.MS_SHARED | syscall.MS_REC,
674-
"rslave": syscall.MS_SLAVE | syscall.MS_REC,
675-
"runbindable": syscall.MS_UNBINDABLE | syscall.MS_REC,
669+
"private": unix.MS_PRIVATE,
670+
"shared": unix.MS_SHARED,
671+
"slave": unix.MS_SLAVE,
672+
"unbindable": unix.MS_UNBINDABLE,
673+
"rprivate": unix.MS_PRIVATE | unix.MS_REC,
674+
"rshared": unix.MS_SHARED | unix.MS_REC,
675+
"rslave": unix.MS_SLAVE | unix.MS_REC,
676+
"runbindable": unix.MS_UNBINDABLE | unix.MS_REC,
676677
}
677678
extensionFlags := map[string]struct {
678679
clear bool

libcontainer/system/linux.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"fmt"
88
"os"
99
"os/exec"
10-
"syscall"
10+
"syscall" // only for exec
1111
"unsafe"
12+
13+
"golang.org/x/sys/unix"
1214
)
1315

1416
// If arg2 is nonzero, set the "child subreaper" attribute of the
@@ -53,48 +55,48 @@ func Execv(cmd string, args []string, env []string) error {
5355
return syscall.Exec(name, args, env)
5456
}
5557

56-
func Prlimit(pid, resource int, limit syscall.Rlimit) error {
57-
_, _, err := syscall.RawSyscall6(syscall.SYS_PRLIMIT64, uintptr(pid), uintptr(resource), uintptr(unsafe.Pointer(&limit)), uintptr(unsafe.Pointer(&limit)), 0, 0)
58+
func Prlimit(pid, resource int, limit unix.Rlimit) error {
59+
_, _, err := unix.RawSyscall6(unix.SYS_PRLIMIT64, uintptr(pid), uintptr(resource), uintptr(unsafe.Pointer(&limit)), uintptr(unsafe.Pointer(&limit)), 0, 0)
5860
if err != 0 {
5961
return err
6062
}
6163
return nil
6264
}
6365

6466
func SetParentDeathSignal(sig uintptr) error {
65-
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_PDEATHSIG, sig, 0); err != 0 {
67+
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_PDEATHSIG, sig, 0); err != 0 {
6668
return err
6769
}
6870
return nil
6971
}
7072

7173
func GetParentDeathSignal() (ParentDeathSignal, error) {
7274
var sig int
73-
_, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0)
75+
_, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0)
7476
if err != 0 {
7577
return -1, err
7678
}
7779
return ParentDeathSignal(sig), nil
7880
}
7981

8082
func SetKeepCaps() error {
81-
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_KEEPCAPS, 1, 0); err != 0 {
83+
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_KEEPCAPS, 1, 0); err != 0 {
8284
return err
8385
}
8486

8587
return nil
8688
}
8789

8890
func ClearKeepCaps() error {
89-
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_KEEPCAPS, 0, 0); err != 0 {
91+
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, unix.PR_SET_KEEPCAPS, 0, 0); err != 0 {
9092
return err
9193
}
9294

9395
return nil
9496
}
9597

9698
func Setctty() error {
97-
if _, _, err := syscall.RawSyscall(syscall.SYS_IOCTL, 0, uintptr(syscall.TIOCSCTTY), 0); err != 0 {
99+
if _, _, err := unix.RawSyscall(unix.SYS_IOCTL, 0, uintptr(unix.TIOCSCTTY), 0); err != 0 {
98100
return err
99101
}
100102
return nil
@@ -135,7 +137,7 @@ func SetSubreaper(i int) error {
135137
}
136138

137139
func Prctl(option int, arg2, arg3, arg4, arg5 uintptr) (err error) {
138-
_, _, e1 := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0)
140+
_, _, e1 := unix.Syscall6(unix.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0)
139141
if e1 != 0 {
140142
err = e1
141143
}

libcontainer/system/setns_linux.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

libcontainer/system/syscall_linux_386.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
package system
44

55
import (
6-
"syscall"
6+
"golang.org/x/sys/unix"
77
)
88

99
// Setuid sets the uid of the calling thread to the specified uid.
1010
func Setuid(uid int) (err error) {
11-
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID32, uintptr(uid), 0, 0)
11+
_, _, e1 := unix.RawSyscall(unix.SYS_SETUID32, uintptr(uid), 0, 0)
1212
if e1 != 0 {
1313
err = e1
1414
}
@@ -17,7 +17,7 @@ func Setuid(uid int) (err error) {
1717

1818
// Setgid sets the gid of the calling thread to the specified gid.
1919
func Setgid(gid int) (err error) {
20-
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETGID32, uintptr(gid), 0, 0)
20+
_, _, e1 := unix.RawSyscall(unix.SYS_SETGID32, uintptr(gid), 0, 0)
2121
if e1 != 0 {
2222
err = e1
2323
}

libcontainer/system/syscall_linux_64.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
package system
44

55
import (
6-
"syscall"
6+
"golang.org/x/sys/unix"
77
)
88

99
// Setuid sets the uid of the calling thread to the specified uid.
1010
func Setuid(uid int) (err error) {
11-
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID, uintptr(uid), 0, 0)
11+
_, _, e1 := unix.RawSyscall(unix.SYS_SETUID, uintptr(uid), 0, 0)
1212
if e1 != 0 {
1313
err = e1
1414
}
@@ -17,7 +17,7 @@ func Setuid(uid int) (err error) {
1717

1818
// Setgid sets the gid of the calling thread to the specified gid.
1919
func Setgid(gid int) (err error) {
20-
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETGID, uintptr(gid), 0, 0)
20+
_, _, e1 := unix.RawSyscall(unix.SYS_SETGID, uintptr(gid), 0, 0)
2121
if e1 != 0 {
2222
err = e1
2323
}

libcontainer/system/syscall_linux_arm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
package system
44

55
import (
6-
"syscall"
6+
"golang.org/x/sys/unix"
77
)
88

99
// Setuid sets the uid of the calling thread to the specified uid.
1010
func Setuid(uid int) (err error) {
11-
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID32, uintptr(uid), 0, 0)
11+
_, _, e1 := unix.RawSyscall(unix.SYS_SETUID32, uintptr(uid), 0, 0)
1212
if e1 != 0 {
1313
err = e1
1414
}
@@ -17,7 +17,7 @@ func Setuid(uid int) (err error) {
1717

1818
// Setgid sets the gid of the calling thread to the specified gid.
1919
func Setgid(gid int) (err error) {
20-
_, _, e1 := syscall.RawSyscall(syscall.SYS_SETGID32, uintptr(gid), 0, 0)
20+
_, _, e1 := unix.RawSyscall(unix.SYS_SETGID32, uintptr(gid), 0, 0)
2121
if e1 != 0 {
2222
err = e1
2323
}

0 commit comments

Comments
 (0)