diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2018-10-04 11:00:40 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-10-04 11:01:44 -0700 |
commit | 4a00ea557c6e60cdd131b2a9866aa3b0bcb9cb2c (patch) | |
tree | be1cec992ce54deb43a2574fb41c160d82e3381e /runsc/main.go | |
parent | 3f46f2e5017106d1569f759b8d19aee6e9827c58 (diff) |
Capture boot panics in debug log.
Docker and Containerd both eat the boot processes stderr, making it difficult
to track down panics (which are always written to stderr).
This CL makes the boot process dup its debug log FD to stderr, so that panics
will be captured in the debug log, which is better than nothing.
This is the 3rd try at this CL. Previous attempts were foiled because Docker
expects the 'create' command to pass its stdio directly to the container, so
duping stderr in 'create' caused the applications stderr to go to the log file,
which breaks many applications (including our mysql test).
I added a new image_test that makes sure stdout and stderr are handled
correctly.
PiperOrigin-RevId: 215767328
Change-Id: Icebac5a5dcf39b623b79d7a0e2f968e059130059
Diffstat (limited to 'runsc/main.go')
-rw-r--r-- | runsc/main.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/runsc/main.go b/runsc/main.go index 2a18c4b9e..16d30f7a0 100644 --- a/runsc/main.go +++ b/runsc/main.go @@ -175,14 +175,30 @@ func main() { cmd.Fatalf("invalid log format %q, must be 'json' or 'text'", *logFormat) } + subcommand := flag.CommandLine.Arg(0) if *debugLogFD > -1 { f := os.NewFile(uintptr(*debugLogFD), "debug log file") + + // Quick sanity check to make sure no other commands get passed + // a log fd (they should use log dir instead). + if subcommand != "boot" { + cmd.Fatalf("flag --debug-log-fd should only be passed to 'boot' command, but was passed to %q", subcommand) + } + + // If we are the boot process, then we own our stdio FDs and + // can do what we want with them. Since Docker and Containerd + // both eat boot's stderr, we dup our stderr to the provided + // log FD so that panics will appear in the logs, rather than + // just disappear. + 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 { cmd.Fatalf("error creating dir %q: %v", *debugLogDir, err) } - subcommand := flag.CommandLine.Arg(0) f, err := specutils.DebugLogFile(*debugLogDir, subcommand) if err != nil { cmd.Fatalf("error opening debug log file in %q: %v", *debugLogDir, err) |