Skip to content

Commit 5fa2e4d

Browse files
author
John Howard
committed
Refactor ProcessConfig
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent 7adfb32 commit 5fa2e4d

File tree

10 files changed

+74
-56
lines changed

10 files changed

+74
-56
lines changed

daemon/container_unix.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
300300
}
301301

302302
processConfig := execdriver.ProcessConfig{
303+
CommonProcessConfig: execdriver.CommonProcessConfig{
304+
Entrypoint: c.Path,
305+
Arguments: c.Args,
306+
Tty: c.Config.Tty,
307+
},
303308
Privileged: c.hostConfig.Privileged,
304-
Entrypoint: c.Path,
305-
Arguments: c.Args,
306-
Tty: c.Config.Tty,
307309
User: c.Config.User,
308310
}
309311

daemon/container_windows.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
8686
},
8787
}
8888

89-
// TODO Windows. Further refactoring required (privileged/user)
9089
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+
},
9695
ConsoleSize: c.hostConfig.ConsoleSize,
9796
}
9897

daemon/exec.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,14 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro
156156
cmd := stringutils.NewStrSlice(config.Cmd...)
157157
entrypoint, args := d.getEntrypointAndArgs(stringutils.NewStrSlice(), cmd)
158158

159-
user := config.User
160-
if len(user) == 0 {
161-
user = container.Config.User
162-
}
163-
164159
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+
},
170165
}
166+
setPlatformSpecificExecProcessConfig(config, container, processConfig)
171167

172168
ExecConfig := &ExecConfig{
173169
ID: stringid.GenerateNonCryptoID(),

daemon/exec_unix.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// +build linux freebsd
2+
3+
package daemon
4+
5+
import (
6+
"github.com/docker/docker/daemon/execdriver"
7+
"github.com/docker/docker/runconfig"
8+
)
9+
10+
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
11+
// ProcessConfig structure.
12+
func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *Container, pc *execdriver.ProcessConfig) {
13+
user := config.User
14+
if len(user) == 0 {
15+
user = container.Config.User
16+
}
17+
18+
pc.User = user
19+
pc.Privileged = config.Privileged
20+
}

daemon/exec_windows.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package daemon
2+
3+
import (
4+
"github.com/docker/docker/daemon/execdriver"
5+
"github.com/docker/docker/runconfig"
6+
)
7+
8+
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
9+
// ProcessConfig structure. This is a no-op on Windows
10+
func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *Container, pc *execdriver.ProcessConfig) {
11+
}

daemon/execdriver/driver.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,15 @@ type ResourceStats struct {
112112
SystemUsage uint64 `json:"system_usage"`
113113
}
114114

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 {
117118
exec.Cmd `json:"-"`
118119

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
127124
}
128125

129126
// CommonCommand is the common platform agnostic part of the Command structure

daemon/execdriver/driver_unix.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ type Resources struct {
4747
MemorySwappiness int64 `json:"memory_swappiness"`
4848
}
4949

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+
5061
// Ipc settings of the container
5162
// It is for IPC namespace setting. Usually different containers
5263
// have their own IPC namespace, however this specifies to use

daemon/execdriver/driver_windows.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ type Resources struct {
1717
// Fields below here are platform specific
1818
}
1919

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+
2029
// Network settings of the container
2130
type Network struct {
2231
Interface *NetworkInterface `json:"interface"`

daemon/execdriver/windows/checkoptions.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

daemon/execdriver/windows/run.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
9494
err error
9595
)
9696

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-
10397
cu := &containerInit{
10498
SystemType: "Container",
10599
Name: c.ID,

0 commit comments

Comments
 (0)