Skip to content

Commit 12f7773

Browse files
author
John Howard
committed
Initial version
Signed-off-by: John Howard <[email protected]>
0 parents  commit 12f7773

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Microsoft
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

docker-signal.exe

2.09 MB
Binary file not shown.

docker-signal.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
// Very simple utility which signals an event. Used to signal a docker
4+
// daemon on Windows to dump its stacks. Usage docker-signal --pid=daemonpid
5+
6+
import (
7+
"flag"
8+
"fmt"
9+
"syscall"
10+
"unsafe"
11+
)
12+
13+
const EVENT_MODIFY_STATUS = 0x0002
14+
15+
var (
16+
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
17+
procOpenEvent = modkernel32.NewProc("OpenEventW")
18+
procPulseEvent = modkernel32.NewProc("PulseEvent")
19+
)
20+
21+
func OpenEvent(desiredAccess uint32, inheritHandle bool, name string) (handle syscall.Handle, err error) {
22+
namep, _ := syscall.UTF16PtrFromString(name)
23+
var _p2 uint32 = 0
24+
if inheritHandle {
25+
_p2 = 1
26+
}
27+
r0, _, e1 := procOpenEvent.Call(uintptr(desiredAccess), uintptr(_p2), uintptr(unsafe.Pointer(namep)))
28+
use(unsafe.Pointer(namep))
29+
handle = syscall.Handle(r0)
30+
if handle == syscall.InvalidHandle {
31+
err = e1
32+
}
33+
return
34+
}
35+
36+
func PulseEvent(handle syscall.Handle) (err error) {
37+
r0, _, _ := procPulseEvent.Call(uintptr(handle))
38+
if r0 != 0 {
39+
err = syscall.Errno(r0)
40+
}
41+
return
42+
}
43+
44+
func main() {
45+
var pid int
46+
flag.IntVar(&pid, "pid", -1, "PID of docker daemon to signal to dump stacks")
47+
flag.Parse()
48+
if pid == -1 {
49+
fmt.Println("Error: pid must be supplied")
50+
return
51+
}
52+
ev := "Global\\docker-daemon-" + fmt.Sprint(pid)
53+
h2, _ := OpenEvent(EVENT_MODIFY_STATUS, false, ev)
54+
if h2 == 0 {
55+
fmt.Printf("Could not open event. Check PID %d is correct and the daemon is running.\n", pid)
56+
return
57+
}
58+
PulseEvent(h2)
59+
fmt.Println("Daemon signalled successfully. Examine its output for stacks")
60+
}
61+
62+
var temp unsafe.Pointer
63+
64+
func use(p unsafe.Pointer) {
65+
temp = p
66+
}

0 commit comments

Comments
 (0)