Browse Source

Merge pull request #17589 from Microsoft/jjh/refactorprocessconfig

Refactor ProcessConfig
David Calavera 9 years ago
parent
commit
8cf38b6a8b

+ 5 - 3
daemon/container_unix.go

@@ -302,10 +302,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,
 	}
 

+ 5 - 6
daemon/container_windows.go

@@ -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,
 	}
 

+ 6 - 10
daemon/exec.go

@@ -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 - 0
daemon/exec_unix.go

@@ -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 - 0
daemon/exec_windows.go

@@ -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) {
+}

+ 7 - 10
daemon/execdriver/driver.go

@@ -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

+ 11 - 0
daemon/execdriver/driver_unix.go

@@ -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

+ 9 - 0
daemon/execdriver/driver_windows.go

@@ -20,6 +20,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"`

+ 0 - 21
daemon/execdriver/windows/checkoptions.go

@@ -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
-}

+ 0 - 6
daemon/execdriver/windows/run.go

@@ -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,