2015-07-07 01:58:53 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"syscall"
|
2016-10-14 00:00:58 +00:00
|
|
|
"unsafe"
|
2015-07-07 01:58:53 +00:00
|
|
|
|
2016-10-14 00:00:58 +00:00
|
|
|
winio "github.com/Microsoft/go-winio"
|
2015-07-07 01:58:53 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-03-28 00:23:34 +00:00
|
|
|
"github.com/docker/docker/pkg/signal"
|
2015-07-07 01:58:53 +00:00
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
|
)
|
|
|
|
|
2016-10-12 22:29:47 +00:00
|
|
|
func (d *Daemon) setupDumpStackTrap(root string) {
|
2015-07-07 01:58:53 +00:00
|
|
|
// Windows does not support signals like *nix systems. So instead of
|
|
|
|
// trapping on SIGUSR1 to dump stacks, we wait on a Win32 event to be
|
2016-10-14 00:00:58 +00:00
|
|
|
// signaled. ACL'd to builtin administrators and local system
|
|
|
|
ev := "Global\\docker-daemon-" + fmt.Sprint(os.Getpid())
|
|
|
|
sd, err := winio.SddlToSecurityDescriptor("D:P(A;;GA;;;BA)(A;;GA;;;SY)")
|
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("failed to get security descriptor for debug stackdump event %s: %s", ev, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var sa syscall.SecurityAttributes
|
|
|
|
sa.Length = uint32(unsafe.Sizeof(sa))
|
|
|
|
sa.InheritHandle = 1
|
|
|
|
sa.SecurityDescriptor = uintptr(unsafe.Pointer(&sd[0]))
|
|
|
|
h, err := system.CreateEvent(&sa, false, false, ev)
|
|
|
|
if h == 0 || err != nil {
|
|
|
|
logrus.Errorf("failed to create debug stackdump event %s: %s", ev, err.Error())
|
|
|
|
return
|
|
|
|
}
|
2015-07-07 01:58:53 +00:00
|
|
|
go func() {
|
2016-10-14 00:00:58 +00:00
|
|
|
logrus.Debugf("Stackdump - waiting signal at %s", ev)
|
|
|
|
for {
|
|
|
|
syscall.WaitForSingleObject(h, syscall.INFINITE)
|
2016-11-01 14:32:55 +00:00
|
|
|
path, err := signal.DumpStacks(root)
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Error("failed to write goroutines dump")
|
2016-10-12 22:29:47 +00:00
|
|
|
} else {
|
|
|
|
logrus.Infof("goroutine stacks written to %s", path)
|
|
|
|
}
|
|
|
|
path, err = d.dumpDaemon(root)
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Error("failed to write daemon datastructure dump")
|
|
|
|
} else {
|
|
|
|
logrus.Infof("daemon datastructure dump written to %s", path)
|
2016-11-01 14:32:55 +00:00
|
|
|
}
|
2015-07-07 01:58:53 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|