2015-05-27 16:15:14 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package windows
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/docker/daemon/execdriver"
|
|
|
|
"github.com/microsoft/hcsshim"
|
|
|
|
)
|
|
|
|
|
2015-08-02 21:54:02 -04:00
|
|
|
// Exec implements the exec driver Driver interface.
|
2015-09-29 13:51:40 -04:00
|
|
|
func (d *Driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessConfig, pipes *execdriver.Pipes, hooks execdriver.Hooks) (int, error) {
|
2015-05-27 16:15:14 -04:00
|
|
|
|
|
|
|
var (
|
2015-07-18 20:15:02 -04:00
|
|
|
term execdriver.Terminal
|
|
|
|
err error
|
|
|
|
exitCode int32
|
2015-05-27 16:15:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
active := d.activeContainers[c.ID]
|
|
|
|
if active == nil {
|
|
|
|
return -1, fmt.Errorf("Exec - No active container exists with ID %s", c.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
createProcessParms := hcsshim.CreateProcessParams{
|
|
|
|
EmulateConsole: processConfig.Tty, // Note NOT c.ProcessConfig.Tty
|
|
|
|
WorkingDirectory: c.WorkingDir,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure the environment for the process // Note NOT c.ProcessConfig.Tty
|
|
|
|
createProcessParms.Environment = setupEnvironmentVariables(processConfig.Env)
|
|
|
|
|
|
|
|
// While this should get caught earlier, just in case, validate that we
|
|
|
|
// have something to run.
|
|
|
|
if processConfig.Entrypoint == "" {
|
|
|
|
err = errors.New("No entrypoint specified")
|
|
|
|
logrus.Error(err)
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the command line of the process
|
|
|
|
createProcessParms.CommandLine = processConfig.Entrypoint
|
|
|
|
for _, arg := range processConfig.Arguments {
|
|
|
|
logrus.Debugln("appending ", arg)
|
|
|
|
createProcessParms.CommandLine += " " + arg
|
|
|
|
}
|
|
|
|
logrus.Debugln("commandLine: ", createProcessParms.CommandLine)
|
|
|
|
|
|
|
|
// Start the command running in the container.
|
2015-07-18 20:15:02 -04:00
|
|
|
pid, stdin, stdout, stderr, err := hcsshim.CreateProcessInComputeSystem(c.ID, pipes.Stdin != nil, true, !processConfig.Tty, createProcessParms)
|
2015-05-27 16:15:14 -04:00
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("CreateProcessInComputeSystem() failed %s", err)
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
|
2015-07-18 20:15:02 -04:00
|
|
|
// Now that the process has been launched, begin copying data to and from
|
|
|
|
// the named pipes for the std handles.
|
|
|
|
setupPipes(stdin, stdout, stderr, pipes)
|
|
|
|
|
2015-05-27 16:15:14 -04:00
|
|
|
// Note NOT c.ProcessConfig.Tty
|
|
|
|
if processConfig.Tty {
|
|
|
|
term = NewTtyConsole(c.ID, pid)
|
|
|
|
} else {
|
|
|
|
term = NewStdConsole()
|
|
|
|
}
|
|
|
|
processConfig.Terminal = term
|
|
|
|
|
|
|
|
// Invoke the start callback
|
2015-09-11 15:05:57 -04:00
|
|
|
if hooks.Start != nil {
|
2015-09-11 06:01:47 -04:00
|
|
|
// A closed channel for OOM is returned here as it will be
|
|
|
|
// non-blocking and return the correct result when read.
|
|
|
|
chOOM := make(chan struct{})
|
|
|
|
close(chOOM)
|
2015-09-29 13:51:40 -04:00
|
|
|
hooks.Start(&c.ProcessConfig, int(pid), chOOM)
|
2015-05-27 16:15:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if exitCode, err = hcsshim.WaitForProcessInComputeSystem(c.ID, pid); err != nil {
|
|
|
|
logrus.Errorf("Failed to WaitForProcessInComputeSystem %s", err)
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Windows - Do something with this exit code
|
|
|
|
logrus.Debugln("Exiting Run() with ExitCode 0", c.ID)
|
|
|
|
return int(exitCode), nil
|
|
|
|
}
|