2015-04-21 00:24:24 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
2016-11-01 10:32:55 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-10-12 18:29:47 -04:00
|
|
|
stackdump "github.com/docker/docker/pkg/signal"
|
2017-05-23 10:22:32 -04:00
|
|
|
"golang.org/x/sys/unix"
|
2015-04-21 00:24:24 -04:00
|
|
|
)
|
|
|
|
|
2016-10-12 18:29:47 -04:00
|
|
|
func (d *Daemon) setupDumpStackTrap(root string) {
|
2015-04-21 00:24:24 -04:00
|
|
|
c := make(chan os.Signal, 1)
|
2017-05-23 10:22:32 -04:00
|
|
|
signal.Notify(c, unix.SIGUSR1)
|
2015-04-21 00:24:24 -04:00
|
|
|
go func() {
|
|
|
|
for range c {
|
2016-11-01 10:32:55 -04:00
|
|
|
path, err := stackdump.DumpStacks(root)
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Error("failed to write goroutines dump")
|
2016-10-12 18:29:47 -04:00
|
|
|
} else {
|
|
|
|
logrus.Infof("goroutine stacks written to %s", path)
|
|
|
|
}
|
2015-04-21 00:24:24 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|