Browse code

Address initial feedback from pr Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/02/26 03:54:41
Showing 5 changed files
... ...
@@ -17,7 +17,7 @@ import (
17 17
 )
18 18
 
19 19
 func main() {
20
-	if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") {
20
+	if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") {
21 21
 		// Running in init mode
22 22
 		sysinit.SysInit()
23 23
 		return
... ...
@@ -2,7 +2,6 @@ package native
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"errors"
6 5
 	"fmt"
7 6
 	"github.com/dotcloud/docker/execdriver"
8 7
 	"github.com/dotcloud/docker/pkg/cgroups"
... ...
@@ -22,10 +21,6 @@ const (
22 22
 	Version    = "0.1"
23 23
 )
24 24
 
25
-var (
26
-	ErrNotSupported = errors.New("not supported")
27
-)
28
-
29 25
 func init() {
30 26
 	execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
31 27
 		var (
... ...
@@ -109,10 +104,13 @@ func (d *driver) Restore(c *execdriver.Command) error {
109 109
 	if err != nil {
110 110
 		return err
111 111
 	}
112
-	defer f.Close()
113 112
 	if _, err := fmt.Fscanf(f, "%d", &nspid); err != nil {
113
+		f.Close()
114 114
 		return err
115 115
 	}
116
+	f.Close()
117
+	defer os.Remove(p)
118
+
116 119
 	proc, err := os.FindProcess(nspid)
117 120
 	if err != nil {
118 121
 		return err
... ...
@@ -85,7 +85,7 @@ func init() {
85 85
 	os.Setenv("TEST", "1")
86 86
 
87 87
 	// Hack to run sys init during unit testing
88
-	if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") {
88
+	if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") {
89 89
 		sysinit.SysInit()
90 90
 		return
91 91
 	}
... ...
@@ -1,11 +1,30 @@
1 1
 package system
2 2
 
3 3
 import (
4
+	"errors"
5
+	"fmt"
6
+	"runtime"
4 7
 	"syscall"
5 8
 )
6 9
 
10
+var (
11
+	ErrNotSupportedPlatform = errors.New("platform and architecture is not supported")
12
+)
13
+
14
+// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092
15
+//
16
+// We need different setns values for the different platforms and arch
17
+// We are declaring the macro here because the SETNS syscall does not exist in th stdlib
18
+var setNsMap = map[string]uintptr{
19
+	"linux/amd64": 308,
20
+}
21
+
7 22
 func Setns(fd uintptr, flags uintptr) error {
8
-	_, _, err := syscall.RawSyscall(SYS_SETNS, fd, flags, 0)
23
+	ns, exists := setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)]
24
+	if !exists {
25
+		return ErrNotSupportedPlatform
26
+	}
27
+	_, _, err := syscall.RawSyscall(ns, fd, flags, 0)
9 28
 	if err != 0 {
10 29
 		return err
11 30
 	}
12 31
deleted file mode 100644
... ...
@@ -1,8 +0,0 @@
1
-// +build linux,amd64
2
-
3
-package system
4
-
5
-// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092
6
-const (
7
-	SYS_SETNS = 308
8
-)