2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2015-07-06 21:58:53 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2016-10-13 20:00:58 -04:00
|
|
|
"unsafe"
|
2015-07-06 21:58:53 -04:00
|
|
|
|
2021-07-15 11:33:55 -04:00
|
|
|
"github.com/docker/docker/pkg/stack"
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-05-23 10:22:32 -04:00
|
|
|
"golang.org/x/sys/windows"
|
2015-07-06 21:58:53 -04:00
|
|
|
)
|
|
|
|
|
2019-08-09 07:19:49 -04:00
|
|
|
func (daemon *Daemon) setupDumpStackTrap(root string) {
|
2015-07-06 21:58:53 -04: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-13 20:00:58 -04:00
|
|
|
// signaled. ACL'd to builtin administrators and local system
|
2019-02-15 18:26:56 -05:00
|
|
|
event := "Global\\stackdump-" + fmt.Sprint(os.Getpid())
|
2017-10-19 14:09:29 -04:00
|
|
|
ev, _ := windows.UTF16PtrFromString(event)
|
2019-09-30 11:07:47 -04:00
|
|
|
sd, err := windows.SecurityDescriptorFromString("D:P(A;;GA;;;BA)(A;;GA;;;SY)")
|
2016-10-13 20:00:58 -04:00
|
|
|
if err != nil {
|
2017-10-19 14:09:29 -04:00
|
|
|
logrus.Errorf("failed to get security descriptor for debug stackdump event %s: %s", event, err.Error())
|
2016-10-13 20:00:58 -04:00
|
|
|
return
|
|
|
|
}
|
2017-05-23 10:22:32 -04:00
|
|
|
var sa windows.SecurityAttributes
|
2016-10-13 20:00:58 -04:00
|
|
|
sa.Length = uint32(unsafe.Sizeof(sa))
|
|
|
|
sa.InheritHandle = 1
|
2019-09-30 11:07:47 -04:00
|
|
|
sa.SecurityDescriptor = sd
|
2017-08-21 06:58:09 -04:00
|
|
|
h, err := windows.CreateEvent(&sa, 0, 0, ev)
|
2016-10-13 20:00:58 -04:00
|
|
|
if h == 0 || err != nil {
|
2017-10-19 14:09:29 -04:00
|
|
|
logrus.Errorf("failed to create debug stackdump event %s: %s", event, err.Error())
|
2016-10-13 20:00:58 -04:00
|
|
|
return
|
|
|
|
}
|
2015-07-06 21:58:53 -04:00
|
|
|
go func() {
|
2017-10-19 14:09:29 -04:00
|
|
|
logrus.Debugf("Stackdump - waiting signal at %s", event)
|
2016-10-13 20:00:58 -04:00
|
|
|
for {
|
2017-05-23 10:22:32 -04:00
|
|
|
windows.WaitForSingleObject(h, windows.INFINITE)
|
2021-07-15 11:33:55 -04:00
|
|
|
path, err := stack.DumpToFile(root)
|
2016-11-01 10:32:55 -04:00
|
|
|
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-07-06 21:58:53 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|