From 0bd720b28dc7b416fe2193bdafaca011ec24d032 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Wed, 16 Nov 2016 12:55:18 -0500 Subject: [PATCH] Move stack dump dir to exec root Dump stack dumps to exec root instead of daemon root. When no path is provided to the stack dumper, such is the case with SIGQUIT, dump to stderr. Signed-off-by: Brian Goff --- daemon/daemon.go | 6 +++++- pkg/signal/trap.go | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 0b9d22c9ed..d66c3b713f 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -693,7 +693,11 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot // set up SIGUSR1 handler on Unix-like systems, or a Win32 global event // on Windows to dump Go routine stacks - d.setupDumpStackTrap(config.Root) + stackDumpDir := config.Root + if execRoot := config.GetExecRoot(); execRoot != "" { + stackDumpDir = execRoot + } + d.setupDumpStackTrap(stackDumpDir) return d, nil } diff --git a/pkg/signal/trap.go b/pkg/signal/trap.go index 44c578aef5..638a1ab66c 100644 --- a/pkg/signal/trap.go +++ b/pkg/signal/trap.go @@ -83,15 +83,21 @@ func DumpStacks(dir string) (string, error) { bufferLen *= 2 } buf = buf[:stackSize] - path := filepath.Join(dir, fmt.Sprintf(stacksLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1))) - f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - return "", errors.Wrap(err, "failed to open file to write the goroutine stacks") + var f *os.File + if dir != "" { + path := filepath.Join(dir, fmt.Sprintf(stacksLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1))) + var err error + f, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666) + if err != nil { + return "", errors.Wrap(err, "failed to open file to write the goroutine stacks") + } + defer f.Close() + defer f.Sync() + } else { + f = os.Stderr } - defer f.Close() if _, err := f.Write(buf); err != nil { return "", errors.Wrap(err, "failed to write goroutine stacks") } - f.Sync() - return path, nil + return f.Name(), nil }