mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
26b1064967
This PR adds a "request ID" to each event generated, the 'docker events' stream now looks like this: ``` 2015-09-10T15:02:50.000000000-07:00 [reqid: c01e3534ddca] de7c5d4ca927253cf4e978ee9c4545161e406e9b5a14617efb52c658b249174a: (from ubuntu) create ``` Note the `[reqID: c01e3534ddca]` part, that's new. Each HTTP request will generate its own unique ID. So, if you do a `docker build` you'll see a series of events all with the same reqID. This allow for log processing tools to determine which events are all related to the same http request. I didn't propigate the context to all possible funcs in the daemon, I decided to just do the ones that needed it in order to get the reqID into the events. I'd like to have people review this direction first, and if we're ok with it then I'll make sure we're consistent about when we pass around the context - IOW, make sure that all funcs at the same level have a context passed in even if they don't call the log funcs - this will ensure we're consistent w/o passing it around for all calls unnecessarily. ping @icecrime @calavera @crosbymichael Signed-off-by: Doug Davis <dug@us.ibm.com>
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
// +build windows
|
|
|
|
package windows
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/docker/docker/context"
|
|
"github.com/docker/docker/daemon/execdriver"
|
|
"github.com/microsoft/hcsshim"
|
|
)
|
|
|
|
// Exec implements the exec driver Driver interface.
|
|
func (d *Driver) Exec(ctx context.Context, c *execdriver.Command, processConfig *execdriver.ProcessConfig, pipes *execdriver.Pipes, hooks execdriver.Hooks) (int, error) {
|
|
|
|
var (
|
|
term execdriver.Terminal
|
|
err error
|
|
exitCode int32
|
|
)
|
|
|
|
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.
|
|
pid, stdin, stdout, stderr, err := hcsshim.CreateProcessInComputeSystem(c.ID, pipes.Stdin != nil, true, !processConfig.Tty, createProcessParms)
|
|
if err != nil {
|
|
logrus.Errorf("CreateProcessInComputeSystem() failed %s", err)
|
|
return -1, err
|
|
}
|
|
|
|
// 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)
|
|
|
|
// Note NOT c.ProcessConfig.Tty
|
|
if processConfig.Tty {
|
|
term = NewTtyConsole(c.ID, pid)
|
|
} else {
|
|
term = NewStdConsole()
|
|
}
|
|
processConfig.Terminal = term
|
|
|
|
// Invoke the start callback
|
|
if hooks.Start != nil {
|
|
// 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)
|
|
hooks.Start(ctx, &c.ProcessConfig, int(pid), chOOM)
|
|
}
|
|
|
|
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
|
|
}
|