github.com/vvnotw/moby@v1.13.1/daemon/debugtrap_windows.go (about) 1 package daemon 2 3 import ( 4 "fmt" 5 "os" 6 "syscall" 7 "unsafe" 8 9 winio "github.com/Microsoft/go-winio" 10 "github.com/Sirupsen/logrus" 11 "github.com/docker/docker/pkg/signal" 12 "github.com/docker/docker/pkg/system" 13 ) 14 15 func (d *Daemon) setupDumpStackTrap(root string) { 16 // Windows does not support signals like *nix systems. So instead of 17 // trapping on SIGUSR1 to dump stacks, we wait on a Win32 event to be 18 // signaled. ACL'd to builtin administrators and local system 19 ev := "Global\\docker-daemon-" + fmt.Sprint(os.Getpid()) 20 sd, err := winio.SddlToSecurityDescriptor("D:P(A;;GA;;;BA)(A;;GA;;;SY)") 21 if err != nil { 22 logrus.Errorf("failed to get security descriptor for debug stackdump event %s: %s", ev, err.Error()) 23 return 24 } 25 var sa syscall.SecurityAttributes 26 sa.Length = uint32(unsafe.Sizeof(sa)) 27 sa.InheritHandle = 1 28 sa.SecurityDescriptor = uintptr(unsafe.Pointer(&sd[0])) 29 h, err := system.CreateEvent(&sa, false, false, ev) 30 if h == 0 || err != nil { 31 logrus.Errorf("failed to create debug stackdump event %s: %s", ev, err.Error()) 32 return 33 } 34 go func() { 35 logrus.Debugf("Stackdump - waiting signal at %s", ev) 36 for { 37 syscall.WaitForSingleObject(h, syscall.INFINITE) 38 path, err := signal.DumpStacks(root) 39 if err != nil { 40 logrus.WithError(err).Error("failed to write goroutines dump") 41 } else { 42 logrus.Infof("goroutine stacks written to %s", path) 43 } 44 path, err = d.dumpDaemon(root) 45 if err != nil { 46 logrus.WithError(err).Error("failed to write daemon datastructure dump") 47 } else { 48 logrus.Infof("daemon datastructure dump written to %s", path) 49 } 50 } 51 }() 52 }