Merge pull request #32244 from Microsoft/jjh/panicfix

Windows - fix panic and stderr output when service
This commit is contained in:
Sebastiaan van Stijn 2017-04-01 20:00:59 +02:00 committed by GitHub
commit a96de091d6
2 changed files with 15 additions and 1 deletions

View File

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

View File

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