[release/1.4.14] cmd/utils: don't check for stderr redirect on windows

The redirect check did not work on Go 1.6 and below because Stat
returned an error for stdout and stderr. In Go 1.7 Stat works on stdout
but doesn't return anything meaningful, causing cmd/geth test failures
because the message is printed to stderr only. Fix it by printing to
stdout only.

(cherry picked from commit b04219fdbb)
This commit is contained in:
Felix Lange 2016-09-26 17:23:26 +02:00 committed by Péter Szilágyi
parent 03b2f56485
commit 25205d64d7
1 changed files with 11 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"regexp" "regexp"
"runtime"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
@ -52,10 +53,16 @@ func openLogFile(Datadir string, filename string) *os.File {
// is redirected to a different file. // is redirected to a different file.
func Fatalf(format string, args ...interface{}) { func Fatalf(format string, args ...interface{}) {
w := io.MultiWriter(os.Stdout, os.Stderr) w := io.MultiWriter(os.Stdout, os.Stderr)
outf, _ := os.Stdout.Stat() if runtime.GOOS == "windows" {
errf, _ := os.Stderr.Stat() // The SameFile check below doesn't work on Windows.
if outf != nil && errf != nil && os.SameFile(outf, errf) { // stdout is unlikely to get redirected though, so just print there.
w = os.Stderr w = os.Stdout
} else {
outf, _ := os.Stdout.Stat()
errf, _ := os.Stderr.Stat()
if outf != nil && errf != nil && os.SameFile(outf, errf) {
w = os.Stderr
}
} }
fmt.Fprintf(w, "Fatal: "+format+"\n", args...) fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
logger.Flush() logger.Flush()