summaryrefslogtreecommitdiffhomepage
path: root/runsc/main.go
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2018-09-07 10:04:11 -0700
committerShentubot <shentubot@google.com>2018-09-07 10:05:21 -0700
commit590d8320992d74e54e2c095c68c49abc2b23dcbe (patch)
treea3150c827d088255ac2a13843520111954a844bb /runsc/main.go
parent6516b5648b471951e8c4da7869531c9509ba1495 (diff)
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: 211992321 Change-Id: I5f0d2f45f35c110a38dab86bafc695aaba42f7a3
Diffstat (limited to 'runsc/main.go')
-rw-r--r--runsc/main.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/runsc/main.go b/runsc/main.go
index 0c9b9af78..c51b199aa 100644
--- a/runsc/main.go
+++ b/runsc/main.go
@@ -179,6 +179,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 {
@@ -189,6 +193,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}}}
}