From d2bc081420173afc65c0f22041fdd23892874678 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 16 Oct 2017 10:36:49 +0200 Subject: [PATCH] libcontainer: merge common syscall implementations There are essentially two possible implementations for Setuid/Setgid on Linux, either using SYS_SETUID32/SYS_SETGID32 or SYS_SETUID/SYS_SETGID, depending on the architecture (see golang/go#1435 for why Setuid/Setgid aren currently implemented for Linux neither in syscall nor in golang.org/x/sys/unix). Reduce duplication by merging the currently implemented variants and adjusting the build tags accordingly. Signed-off-by: Tobias Klauser --- ...scall_linux_386.go => syscall_linux_32.go} | 3 ++- libcontainer/system/syscall_linux_64.go | 3 ++- libcontainer/system/syscall_linux_arm.go | 25 ------------------- libcontainer/system/syscall_linux_mipsx.go | 25 ------------------- 4 files changed, 4 insertions(+), 52 deletions(-) rename libcontainer/system/{syscall_linux_386.go => syscall_linux_32.go} (93%) delete mode 100644 libcontainer/system/syscall_linux_arm.go delete mode 100644 libcontainer/system/syscall_linux_mipsx.go diff --git a/libcontainer/system/syscall_linux_386.go b/libcontainer/system/syscall_linux_32.go similarity index 93% rename from libcontainer/system/syscall_linux_386.go rename to libcontainer/system/syscall_linux_32.go index 3f7235ed1..c5ca5d862 100644 --- a/libcontainer/system/syscall_linux_386.go +++ b/libcontainer/system/syscall_linux_32.go @@ -1,4 +1,5 @@ -// +build linux,386 +// +build linux +// +build 386 arm package system diff --git a/libcontainer/system/syscall_linux_64.go b/libcontainer/system/syscall_linux_64.go index d7891a2ff..11c3faafb 100644 --- a/libcontainer/system/syscall_linux_64.go +++ b/libcontainer/system/syscall_linux_64.go @@ -1,4 +1,5 @@ -// +build linux,arm64 linux,amd64 linux,ppc linux,ppc64 linux,ppc64le linux,s390x +// +build linux +// +build arm64 amd64 mips mipsle mips64 mips64le ppc ppc64 ppc64le s390x package system diff --git a/libcontainer/system/syscall_linux_arm.go b/libcontainer/system/syscall_linux_arm.go deleted file mode 100644 index 31ff3deb1..000000000 --- a/libcontainer/system/syscall_linux_arm.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build linux,arm - -package system - -import ( - "golang.org/x/sys/unix" -) - -// Setuid sets the uid of the calling thread to the specified uid. -func Setuid(uid int) (err error) { - _, _, e1 := unix.RawSyscall(unix.SYS_SETUID32, uintptr(uid), 0, 0) - if e1 != 0 { - err = e1 - } - return -} - -// Setgid sets the gid of the calling thread to the specified gid. -func Setgid(gid int) (err error) { - _, _, e1 := unix.RawSyscall(unix.SYS_SETGID32, uintptr(gid), 0, 0) - if e1 != 0 { - err = e1 - } - return -} diff --git a/libcontainer/system/syscall_linux_mipsx.go b/libcontainer/system/syscall_linux_mipsx.go deleted file mode 100644 index 98a3f088b..000000000 --- a/libcontainer/system/syscall_linux_mipsx.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build linux,mips linux,mipsle linux,mips64 linux,mips64le - -package system - -import ( - "syscall" -) - -// Setuid sets the uid of the calling thread to the specified uid. -func Setuid(uid int) (err error) { - _, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID, uintptr(uid), 0, 0) - if e1 != 0 { - err = e1 - } - return -} - -// Setgid sets the gid of the calling thread to the specified gid. -func Setgid(gid int) (err error) { - _, _, e1 := syscall.RawSyscall(syscall.SYS_SETGID, uintptr(gid), 0, 0) - if e1 != 0 { - err = e1 - } - return -}