From 5982af496947d5049b7b20caf6ebfd5071d1ef6d Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Tue, 25 Feb 2014 10:54:41 -0800 Subject: [PATCH] Address initial feedback from pr Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- system/setns_linux.go | 21 ++++++++++++++++++++- system/setns_linux_amd64.go | 8 -------- 2 files changed, 20 insertions(+), 9 deletions(-) delete mode 100644 system/setns_linux_amd64.go diff --git a/system/setns_linux.go b/system/setns_linux.go index be6f3ed..07b1c93 100644 --- a/system/setns_linux.go +++ b/system/setns_linux.go @@ -1,11 +1,30 @@ package system import ( + "errors" + "fmt" + "runtime" "syscall" ) +var ( + ErrNotSupportedPlatform = errors.New("platform and architecture is not supported") +) + +// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092 +// +// We need different setns values for the different platforms and arch +// We are declaring the macro here because the SETNS syscall does not exist in th stdlib +var setNsMap = map[string]uintptr{ + "linux/amd64": 308, +} + func Setns(fd uintptr, flags uintptr) error { - _, _, err := syscall.RawSyscall(SYS_SETNS, fd, flags, 0) + ns, exists := setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)] + if !exists { + return ErrNotSupportedPlatform + } + _, _, err := syscall.RawSyscall(ns, fd, flags, 0) if err != 0 { return err } diff --git a/system/setns_linux_amd64.go b/system/setns_linux_amd64.go deleted file mode 100644 index 4e30625..0000000 --- a/system/setns_linux_amd64.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build linux,amd64 - -package system - -// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092 -const ( - SYS_SETNS = 308 -)