github.com/gondor/docker@v1.9.0-rc1/daemon/execdriver/windows/exec.go (about) 1 // +build windows 2 3 package windows 4 5 import ( 6 "errors" 7 "fmt" 8 9 "github.com/Sirupsen/logrus" 10 "github.com/docker/docker/daemon/execdriver" 11 "github.com/microsoft/hcsshim" 12 ) 13 14 // Exec implements the exec driver Driver interface. 15 func (d *Driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessConfig, pipes *execdriver.Pipes, hooks execdriver.Hooks) (int, error) { 16 17 var ( 18 term execdriver.Terminal 19 err error 20 exitCode int32 21 ) 22 23 active := d.activeContainers[c.ID] 24 if active == nil { 25 return -1, fmt.Errorf("Exec - No active container exists with ID %s", c.ID) 26 } 27 28 createProcessParms := hcsshim.CreateProcessParams{ 29 EmulateConsole: processConfig.Tty, // Note NOT c.ProcessConfig.Tty 30 WorkingDirectory: c.WorkingDir, 31 } 32 33 // Configure the environment for the process // Note NOT c.ProcessConfig.Tty 34 createProcessParms.Environment = setupEnvironmentVariables(processConfig.Env) 35 36 // While this should get caught earlier, just in case, validate that we 37 // have something to run. 38 if processConfig.Entrypoint == "" { 39 err = errors.New("No entrypoint specified") 40 logrus.Error(err) 41 return -1, err 42 } 43 44 // Build the command line of the process 45 createProcessParms.CommandLine = processConfig.Entrypoint 46 for _, arg := range processConfig.Arguments { 47 logrus.Debugln("appending ", arg) 48 createProcessParms.CommandLine += " " + arg 49 } 50 logrus.Debugln("commandLine: ", createProcessParms.CommandLine) 51 52 // Start the command running in the container. 53 pid, stdin, stdout, stderr, err := hcsshim.CreateProcessInComputeSystem(c.ID, pipes.Stdin != nil, true, !processConfig.Tty, createProcessParms) 54 if err != nil { 55 logrus.Errorf("CreateProcessInComputeSystem() failed %s", err) 56 return -1, err 57 } 58 59 // Now that the process has been launched, begin copying data to and from 60 // the named pipes for the std handles. 61 setupPipes(stdin, stdout, stderr, pipes) 62 63 // Note NOT c.ProcessConfig.Tty 64 if processConfig.Tty { 65 term = NewTtyConsole(c.ID, pid) 66 } else { 67 term = NewStdConsole() 68 } 69 processConfig.Terminal = term 70 71 // Invoke the start callback 72 if hooks.Start != nil { 73 // A closed channel for OOM is returned here as it will be 74 // non-blocking and return the correct result when read. 75 chOOM := make(chan struct{}) 76 close(chOOM) 77 hooks.Start(&c.ProcessConfig, int(pid), chOOM) 78 } 79 80 if exitCode, err = hcsshim.WaitForProcessInComputeSystem(c.ID, pid); err != nil { 81 logrus.Errorf("Failed to WaitForProcessInComputeSystem %s", err) 82 return -1, err 83 } 84 85 // TODO Windows - Do something with this exit code 86 logrus.Debugln("Exiting Run() with ExitCode 0", c.ID) 87 return int(exitCode), nil 88 }