diff --git a/main.go b/main.go index b789f08c..fd1ad5ff 100644 --- a/main.go +++ b/main.go @@ -159,7 +159,10 @@ type FatalWriter struct { func (f *FatalWriter) Write(p []byte) (n int, err error) { logrus.Error(string(p)) - return f.cliErrWriter.Write(p) + if !logrusToStderr() { + return f.cliErrWriter.Write(p) + } + return len(p), nil } func createLogConfig(context *cli.Context) logs.Config { diff --git a/utils.go b/utils.go index 5165336f..c687a478 100644 --- a/utils.go +++ b/utils.go @@ -45,12 +45,20 @@ func checkArgs(context *cli.Context, expected, checkType int) error { return nil } +func logrusToStderr() bool { + l, ok := logrus.StandardLogger().Out.(*os.File) + return ok && l.Fd() == os.Stderr.Fd() +} + // fatal prints the error's details if it is a libcontainer specific error type // then exits the program with an exit status of 1. func fatal(err error) { // make sure the error is written to the logger logrus.Error(err) - fmt.Fprintln(os.Stderr, err) + if !logrusToStderr() { + fmt.Fprintln(os.Stderr, err) + } + os.Exit(1) }