Refactor ProcessConfig

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2015-11-01 07:53:15 -08:00
parent 7adfb3221e
commit 5fa2e4d4f2
10 changed files with 74 additions and 56 deletions

View File

@ -300,10 +300,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
}
processConfig := execdriver.ProcessConfig{
CommonProcessConfig: execdriver.CommonProcessConfig{
Entrypoint: c.Path,
Arguments: c.Args,
Tty: c.Config.Tty,
},
Privileged: c.hostConfig.Privileged,
Entrypoint: c.Path,
Arguments: c.Args,
Tty: c.Config.Tty,
User: c.Config.User,
}

View File

@ -86,13 +86,12 @@ func (daemon *Daemon) populateCommand(c *Container, env []string) error {
},
}
// TODO Windows. Further refactoring required (privileged/user)
processConfig := execdriver.ProcessConfig{
Privileged: c.hostConfig.Privileged,
Entrypoint: c.Path,
Arguments: c.Args,
Tty: c.Config.Tty,
User: c.Config.User,
CommonProcessConfig: execdriver.CommonProcessConfig{
Entrypoint: c.Path,
Arguments: c.Args,
Tty: c.Config.Tty,
},
ConsoleSize: c.hostConfig.ConsoleSize,
}

View File

@ -156,18 +156,14 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro
cmd := stringutils.NewStrSlice(config.Cmd...)
entrypoint, args := d.getEntrypointAndArgs(stringutils.NewStrSlice(), cmd)
user := config.User
if len(user) == 0 {
user = container.Config.User
}
processConfig := &execdriver.ProcessConfig{
Tty: config.Tty,
Entrypoint: entrypoint,
Arguments: args,
User: user,
Privileged: config.Privileged,
CommonProcessConfig: execdriver.CommonProcessConfig{
Tty: config.Tty,
Entrypoint: entrypoint,
Arguments: args,
},
}
setPlatformSpecificExecProcessConfig(config, container, processConfig)
ExecConfig := &ExecConfig{
ID: stringid.GenerateNonCryptoID(),

20
daemon/exec_unix.go Normal file
View File

@ -0,0 +1,20 @@
// +build linux freebsd
package daemon
import (
"github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/runconfig"
)
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
// ProcessConfig structure.
func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *Container, pc *execdriver.ProcessConfig) {
user := config.User
if len(user) == 0 {
user = container.Config.User
}
pc.User = user
pc.Privileged = config.Privileged
}

11
daemon/exec_windows.go Normal file
View File

@ -0,0 +1,11 @@
package daemon
import (
"github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/runconfig"
)
// setPlatformSpecificExecProcessConfig sets platform-specific fields in the
// ProcessConfig structure. This is a no-op on Windows
func setPlatformSpecificExecProcessConfig(config *runconfig.ExecConfig, container *Container, pc *execdriver.ProcessConfig) {
}

View File

@ -112,18 +112,15 @@ type ResourceStats struct {
SystemUsage uint64 `json:"system_usage"`
}
// ProcessConfig describes a process that will be run inside a container.
type ProcessConfig struct {
// CommonProcessConfig is the common platform agnostic part of the ProcessConfig
// structure that describes a process that will be run inside a container.
type CommonProcessConfig struct {
exec.Cmd `json:"-"`
Privileged bool `json:"privileged"`
User string `json:"user"`
Tty bool `json:"tty"`
Entrypoint string `json:"entrypoint"`
Arguments []string `json:"arguments"`
Terminal Terminal `json:"-"` // standard or tty terminal (Unix)
Console string `json:"-"` // dev/console path (Unix)
ConsoleSize [2]int `json:"-"` // h,w of initial console size (Windows)
Tty bool `json:"tty"`
Entrypoint string `json:"entrypoint"`
Arguments []string `json:"arguments"`
Terminal Terminal `json:"-"` // standard or tty terminal
}
// CommonCommand is the common platform agnostic part of the Command structure

View File

@ -47,6 +47,17 @@ type Resources struct {
MemorySwappiness int64 `json:"memory_swappiness"`
}
// ProcessConfig is the platform specific structure that describes a process
// that will be run inside a container.
type ProcessConfig struct {
CommonProcessConfig
// Fields below here are platform specific
Privileged bool `json:"privileged"`
User string `json:"user"`
Console string `json:"-"` // dev/console path
}
// Ipc settings of the container
// It is for IPC namespace setting. Usually different containers
// have their own IPC namespace, however this specifies to use

View File

@ -17,6 +17,15 @@ type Resources struct {
// Fields below here are platform specific
}
// ProcessConfig is the platform specific structure that describes a process
// that will be run inside a container.
type ProcessConfig struct {
CommonProcessConfig
// Fields below here are platform specific
ConsoleSize [2]int `json:"-"` // h,w of initial console size
}
// Network settings of the container
type Network struct {
Interface *NetworkInterface `json:"interface"`

View File

@ -1,21 +0,0 @@
// +build windows
package windows
import (
"errors"
"github.com/docker/docker/daemon/execdriver"
)
func checkSupportedOptions(c *execdriver.Command) error {
// Windows doesn't support username
if c.ProcessConfig.User != "" {
return errors.New("Windows does not support the username option")
}
// TODO Windows: Validate other fields which Windows doesn't support, factor
// out where applicable per platform.
return nil
}

View File

@ -94,12 +94,6 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
err error
)
// Make sure the client isn't asking for options which aren't supported
err = checkSupportedOptions(c)
if err != nil {
return execdriver.ExitStatus{ExitCode: -1}, err
}
cu := &containerInit{
SystemType: "Container",
Name: c.ID,