From 75453ad8e75afaca2d6e5e5021cd57c3dc03a6ef Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 30 Mar 2017 15:36:42 -0700 Subject: [PATCH] Windows - fix panic and stderr Signed-off-by: John Howard Upstream-commit: 141a83b820140fac130840b2a0ea9df75ab4e55d Component: engine --- components/engine/cmd/dockerd/docker.go | 9 ++++++++- components/engine/cmd/dockerd/service_windows.go | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/engine/cmd/dockerd/docker.go b/components/engine/cmd/dockerd/docker.go index 0bde86d203..c794748213 100644 --- a/components/engine/cmd/dockerd/docker.go +++ b/components/engine/cmd/dockerd/docker.go @@ -104,7 +104,14 @@ func main() { // Set terminal emulation based on platform as required. _, stdout, stderr := term.StdStreams() - logrus.SetOutput(stderr) + + // @jhowardmsft - maybe there is a historic reason why on non-Windows, stderr is used + // here. However, on Windows it makes no sense and there is no need. + if runtime.GOOS == "windows" { + logrus.SetOutput(stdout) + } else { + logrus.SetOutput(stderr) + } cmd := newDaemonCommand() cmd.SetOutput(stdout) diff --git a/components/engine/cmd/dockerd/service_windows.go b/components/engine/cmd/dockerd/service_windows.go index 3d038fad79..749cc9009e 100644 --- a/components/engine/cmd/dockerd/service_windows.go +++ b/components/engine/cmd/dockerd/service_windows.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io/ioutil" + "log" "os" "os/exec" "path/filepath" @@ -409,6 +410,12 @@ func initPanicFile(path string) error { return err } + // Reset os.Stderr to the panic file (so fmt.Fprintf(os.Stderr,...) actually gets redirected) + os.Stderr = os.NewFile(uintptr(panicFile.Fd()), "/dev/stderr") + + // Force threads that panic to write to stderr (the panicFile handle now), otherwise it will go into the ether + log.SetOutput(os.Stderr) + return nil }