From de083400b8d7c2074d71a30a92e4f3c8bcd8bad8 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) --- docker/docker.go | 2 +- execdriver/native/driver.go | 10 ++++------ integration/runtime_test.go | 2 +- pkg/system/setns_linux.go | 21 ++++++++++++++++++++- pkg/system/setns_linux_amd64.go | 8 -------- 5 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 pkg/system/setns_linux_amd64.go diff --git a/docker/docker.go b/docker/docker.go index a2d83bfa86..3ea3d63027 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -17,7 +17,7 @@ import ( ) func main() { - if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") { + if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") { // Running in init mode sysinit.SysInit() return diff --git a/execdriver/native/driver.go b/execdriver/native/driver.go index a10125c120..16e5ea1b49 100644 --- a/execdriver/native/driver.go +++ b/execdriver/native/driver.go @@ -2,7 +2,6 @@ package native import ( "encoding/json" - "errors" "fmt" "github.com/dotcloud/docker/execdriver" "github.com/dotcloud/docker/pkg/cgroups" @@ -22,10 +21,6 @@ const ( Version = "0.1" ) -var ( - ErrNotSupported = errors.New("not supported") -) - func init() { execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error { var ( @@ -109,10 +104,13 @@ func (d *driver) Restore(c *execdriver.Command) error { if err != nil { return err } - defer f.Close() if _, err := fmt.Fscanf(f, "%d", &nspid); err != nil { + f.Close() return err } + f.Close() + defer os.Remove(p) + proc, err := os.FindProcess(nspid) if err != nil { return err diff --git a/integration/runtime_test.go b/integration/runtime_test.go index 060980f4e1..6003c89b51 100644 --- a/integration/runtime_test.go +++ b/integration/runtime_test.go @@ -85,7 +85,7 @@ func init() { os.Setenv("TEST", "1") // Hack to run sys init during unit testing - if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") { + if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") { sysinit.SysInit() return } diff --git a/pkg/system/setns_linux.go b/pkg/system/setns_linux.go index be6f3edb30..07b1c93b4a 100644 --- a/pkg/system/setns_linux.go +++ b/pkg/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/pkg/system/setns_linux_amd64.go b/pkg/system/setns_linux_amd64.go deleted file mode 100644 index 4e306253d9..0000000000 --- a/pkg/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 -)