2021-08-23 13:14:53 +00:00
|
|
|
//go:build !windows
|
2015-04-21 04:24:24 +00:00
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2015-04-21 04:24:24 +00:00
|
|
|
|
|
|
|
import (
|
2023-06-23 00:33:17 +00:00
|
|
|
"context"
|
2015-04-21 04:24:24 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
2023-09-13 15:41:45 +00:00
|
|
|
"github.com/containerd/log"
|
2021-07-15 15:33:55 +00:00
|
|
|
"github.com/docker/docker/pkg/stack"
|
2017-05-23 14:22:32 +00:00
|
|
|
"golang.org/x/sys/unix"
|
2015-04-21 04:24:24 +00:00
|
|
|
)
|
|
|
|
|
2019-08-09 11:19:49 +00:00
|
|
|
func (daemon *Daemon) setupDumpStackTrap(root string) {
|
2015-04-21 04:24:24 +00:00
|
|
|
c := make(chan os.Signal, 1)
|
2017-05-23 14:22:32 +00:00
|
|
|
signal.Notify(c, unix.SIGUSR1)
|
2015-04-21 04:24:24 +00:00
|
|
|
go func() {
|
|
|
|
for range c {
|
2021-07-15 15:33:55 +00:00
|
|
|
path, err := stack.DumpToFile(root)
|
2016-11-01 14:32:55 +00:00
|
|
|
if err != nil {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(context.TODO()).WithError(err).Error("failed to write goroutines dump")
|
2016-10-12 22:29:47 +00:00
|
|
|
} else {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(context.TODO()).Infof("goroutine stacks written to %s", path)
|
2016-10-12 22:29:47 +00:00
|
|
|
}
|
2015-04-21 04:24:24 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|