1
0
mirror of https://github.com/docker/cli.git synced 2026-01-13 18:22:35 +03:00

Merge pull request #28487 from cpuguy83/stack_dumps

Move stack dump dir to exec root
Upstream-commit: 6367c67ab71916d677d3498f0bb536da9ae63597
Component: engine
This commit is contained in:
Vincent Demeester
2016-11-30 20:01:29 +01:00
committed by GitHub
2 changed files with 18 additions and 8 deletions

View File

@@ -692,7 +692,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
}

View File

@@ -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
}