debugtrap_unix.go 603 B

12345678910111213141516171819202122232425262728
  1. //go:build !windows
  2. package daemon // import "github.com/docker/docker/daemon"
  3. import (
  4. "context"
  5. "os"
  6. "os/signal"
  7. "github.com/containerd/log"
  8. "github.com/docker/docker/pkg/stack"
  9. "golang.org/x/sys/unix"
  10. )
  11. func (daemon *Daemon) setupDumpStackTrap(root string) {
  12. c := make(chan os.Signal, 1)
  13. signal.Notify(c, unix.SIGUSR1)
  14. go func() {
  15. for range c {
  16. path, err := stack.DumpToFile(root)
  17. if err != nil {
  18. log.G(context.TODO()).WithError(err).Error("failed to write goroutines dump")
  19. } else {
  20. log.G(context.TODO()).Infof("goroutine stacks written to %s", path)
  21. }
  22. }
  23. }()
  24. }