debugtrap_unix.go 506 B

12345678910111213141516171819202122232425262728
  1. // +build !windows
  2. package daemon
  3. import (
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. stackdump "github.com/docker/docker/pkg/signal"
  8. "github.com/Sirupsen/logrus"
  9. )
  10. func setupDumpStackTrap(root string) {
  11. c := make(chan os.Signal, 1)
  12. signal.Notify(c, syscall.SIGUSR1)
  13. go func() {
  14. for range c {
  15. path, err := stackdump.DumpStacks(root)
  16. if err != nil {
  17. logrus.WithError(err).Error("failed to write goroutines dump")
  18. continue
  19. }
  20. logrus.Infof("goroutine stacks written to %s", path)
  21. }
  22. }()
  23. }