Browse code

Refactor ProcessConfig

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2015/11/02 00:53:15
Showing 10 changed files
... ...
@@ -300,10 +300,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
300 300
 	}
301 301
 
302 302
 	processConfig := execdriver.ProcessConfig{
303
+		CommonProcessConfig: execdriver.CommonProcessConfig{
304
+			Entrypoint: c.Path,
305
+			Arguments:  c.Args,
306
+			Tty:        c.Config.Tty,
307
+		},
303 308
 		Privileged: c.hostConfig.Privileged,
304
-		Entrypoint: c.Path,
305
-		Arguments:  c.Args,
306
-		Tty:        c.Config.Tty,
307 309
 		User:       c.Config.User,
308 310
 	}
309 311
 
... ...
@@ -86,13 +86,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
86 86
 		},
87 87
 	}
88 88
 
89
-	// TODO Windows. Further refactoring required (privileged/user)
90 89
 	processConfig := execdriver.ProcessConfig{
91
-		Privileged:  c.hostConfig.Privileged,
92
-		Entrypoint:  c.Path,
93
-		Arguments:   c.Args,
94
-		Tty:         c.Config.Tty,
95
-		User:        c.Config.User,
90
+		CommonProcessConfig: execdriver.CommonProcessConfig{
91
+			Entrypoint: c.Path,
92
+			Arguments:  c.Args,
93
+			Tty:        c.Config.Tty,
94
+		},
96 95
 		ConsoleSize: c.hostConfig.ConsoleSize,
97 96
 	}
98 97
 
... ...
@@ -156,18 +156,14 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro
156 156
 	cmd := stringutils.NewStrSlice(config.Cmd...)
157 157
 	entrypoint, args := d.getEntrypointAndArgs(stringutils.NewStrSlice(), cmd)
158 158
 
159
-	user := config.User
160
-	if len(user) == 0 {
161
-		user = container.Config.User
162
-	}
163
-
164 159
 	processConfig := &execdriver.ProcessConfig{
165
-		Tty:        config.Tty,
166
-		Entrypoint: entrypoint,
167
-		Arguments:  args,
168
-		User:       user,
169
-		Privileged: config.Privileged,
160
+		CommonProcessConfig: execdriver.CommonProcessConfig{
161
+			Tty:        config.Tty,
162
+			Entrypoint: entrypoint,
163
+			Arguments:  args,
164
+		},
170 165
 	}
166
+	setPlatformSpecificExecProcessConfig(config, container, processConfig)
171 167
 
172 168
 	ExecConfig := &ExecConfig{
173 169
 		ID:            stringid.GenerateNonCryptoID(),
174 170
new file mode 100644
... ...
@@ -0,0 +1,20 @@
0
+// +build linux freebsd
1
+
2
+package daemon
3
+
4
+import (
5
+	"github.com/docker/docker/daemon/execdriver"
6
+	"github.com/docker/docker/runconfig"
7
+)
8
+
9
+// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
10
+// ProcessConfig structure.
11
+func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *Container, pc *execdriver.ProcessConfig) {
12
+	user := config.User
13
+	if len(user) == 0 {
14
+		user = container.Config.User
15
+	}
16
+
17
+	pc.User = user
18
+	pc.Privileged = config.Privileged
19
+}
0 20
new file mode 100644
... ...
@@ -0,0 +1,11 @@
0
+package daemon
1
+
2
+import (
3
+	"github.com/docker/docker/daemon/execdriver"
4
+	"github.com/docker/docker/runconfig"
5
+)
6
+
7
+// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
8
+// ProcessConfig structure. This is a no-op on Windows
9
+func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *Container, pc *execdriver.ProcessConfig) {
10
+}
... ...
@@ -112,18 +112,15 @@ type ResourceStats struct {
112 112
 	SystemUsage uint64    `json:"system_usage"`
113 113
 }
114 114
 
115
-// ProcessConfig describes a process that will be run inside a container.
116
-type ProcessConfig struct {
115
+// CommonProcessConfig is the common platform agnostic part of the ProcessConfig
116
+// structure that describes a process that will be run inside a container.
117
+type CommonProcessConfig struct {
117 118
 	exec.Cmd `json:"-"`
118 119
 
119
-	Privileged  bool     `json:"privileged"`
120
-	User        string   `json:"user"`
121
-	Tty         bool     `json:"tty"`
122
-	Entrypoint  string   `json:"entrypoint"`
123
-	Arguments   []string `json:"arguments"`
124
-	Terminal    Terminal `json:"-"` // standard or tty terminal (Unix)
125
-	Console     string   `json:"-"` // dev/console path (Unix)
126
-	ConsoleSize [2]int   `json:"-"` // h,w of initial console size (Windows)
120
+	Tty        bool     `json:"tty"`
121
+	Entrypoint string   `json:"entrypoint"`
122
+	Arguments  []string `json:"arguments"`
123
+	Terminal   Terminal `json:"-"` // standard or tty terminal
127 124
 }
128 125
 
129 126
 // CommonCommand is the common platform agnostic part of the Command structure
... ...
@@ -47,6 +47,17 @@ type Resources struct {
47 47
 	MemorySwappiness int64            `json:"memory_swappiness"`
48 48
 }
49 49
 
50
+// ProcessConfig is the platform specific structure that describes a process
51
+// that will be run inside a container.
52
+type ProcessConfig struct {
53
+	CommonProcessConfig
54
+
55
+	// Fields below here are platform specific
56
+	Privileged bool   `json:"privileged"`
57
+	User       string `json:"user"`
58
+	Console    string `json:"-"` // dev/console path
59
+}
60
+
50 61
 // Ipc settings of the container
51 62
 // It is for IPC namespace setting. Usually different containers
52 63
 // have their own IPC namespace, however this specifies to use
... ...
@@ -17,6 +17,15 @@ type Resources struct {
17 17
 	// Fields below here are platform specific
18 18
 }
19 19
 
20
+// ProcessConfig is the platform specific structure that describes a process
21
+// that will be run inside a container.
22
+type ProcessConfig struct {
23
+	CommonProcessConfig
24
+
25
+	// Fields below here are platform specific
26
+	ConsoleSize [2]int `json:"-"` // h,w of initial console size
27
+}
28
+
20 29
 // Network settings of the container
21 30
 type Network struct {
22 31
 	Interface   *NetworkInterface `json:"interface"`
23 32
deleted file mode 100644
... ...
@@ -1,21 +0,0 @@
1
-// +build windows
2
-
3
-package windows
4
-
5
-import (
6
-	"errors"
7
-
8
-	"github.com/docker/docker/daemon/execdriver"
9
-)
10
-
11
-func checkSupportedOptions(c *execdriver.Command) error {
12
-	// Windows doesn't support username
13
-	if c.ProcessConfig.User != "" {
14
-		return errors.New("Windows does not support the username option")
15
-	}
16
-
17
-	// TODO Windows: Validate other fields which Windows doesn't support, factor
18
-	// out where applicable per platform.
19
-
20
-	return nil
21
-}
... ...
@@ -94,12 +94,6 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
94 94
 		err  error
95 95
 	)
96 96
 
97
-	// Make sure the client isn't asking for options which aren't supported
98
-	err = checkSupportedOptions(c)
99
-	if err != nil {
100
-		return execdriver.ExitStatus{ExitCode: -1}, err
101
-	}
102
-
103 97
 	cu := &containerInit{
104 98
 		SystemType:              "Container",
105 99
 		Name:                    c.ID,