runsc: Dup debug log file to stderr, so sentry panics don't get lost.

Docker and containerd do not expose runsc's stderr, so tracking down sentry
panics can be painful.

If we have a debug log file, we should send panics (and all stderr data) to the
log file.

PiperOrigin-RevId: 215585559
Change-Id: I3844259ed0cd26e26422bcdb40dded302740b8b6
This commit is contained in:
Nicolas Lacasse 2018-10-03 10:32:35 -07:00 committed by Shentubot
parent e215b9970a
commit 55d28fb124
1 changed files with 8 additions and 0 deletions

View File

@ -177,6 +177,10 @@ func main() {
if *debugLogFD > -1 {
f := os.NewFile(uintptr(*debugLogFD), "debug log file")
// Dup f to stderr so we capture stack traces on panic.
if err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd())); err != nil {
cmd.Fatalf("error dup'ing fd %d to stderr: %v", f.Fd(), err)
}
e = log.MultiEmitter{e, log.GoogleEmitter{&log.Writer{Next: f}}}
} else if *debugLogDir != "" {
if err := os.MkdirAll(*debugLogDir, 0775); err != nil {
@ -187,6 +191,10 @@ func main() {
if err != nil {
cmd.Fatalf("error opening debug log file in %q: %v", *debugLogDir, err)
}
// Dup f to stderr so we capture stack traces on panic.
if err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd())); err != nil {
cmd.Fatalf("error dup'ing fd %d to stderr: %v", f.Fd(), err)
}
e = log.MultiEmitter{e, log.GoogleEmitter{&log.Writer{Next: f}}}
}