Introduce containerd-shim-runhcs-v1 on Windows
Implements the containerd-shim-runhcs-v1 shim on Windows for the runtime v2 shim API. Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/containerd/containerd/events"
|
||||
@@ -35,6 +36,7 @@ import (
|
||||
"github.com/containerd/typeurl"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// setupSignals creates a new signal handler for all signals
|
||||
@@ -51,8 +53,43 @@ func subreaper() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type fakeSignal struct {
|
||||
}
|
||||
|
||||
func (fs *fakeSignal) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (fs *fakeSignal) Signal() {
|
||||
}
|
||||
|
||||
func setupDumpStacks(dump chan<- os.Signal) {
|
||||
// TODO: JTERRY75: Make this based on events. signal.Notify(dump, syscall.SIGUSR1)
|
||||
// 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
|
||||
// signaled. ACL'd to builtin administrators and local system
|
||||
event := "Global\\containerd-shim-runhcs-v1-" + fmt.Sprint(os.Getpid())
|
||||
ev, _ := windows.UTF16PtrFromString(event)
|
||||
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", event, err.Error())
|
||||
return
|
||||
}
|
||||
var sa windows.SecurityAttributes
|
||||
sa.Length = uint32(unsafe.Sizeof(sa))
|
||||
sa.InheritHandle = 1
|
||||
sa.SecurityDescriptor = uintptr(unsafe.Pointer(&sd[0]))
|
||||
h, err := windows.CreateEvent(&sa, 0, 0, ev)
|
||||
if h == 0 || err != nil {
|
||||
logrus.Errorf("failed to create debug stackdump event %s: %s", event, err.Error())
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
logrus.Debugf("Stackdump - waiting signal at %s", event)
|
||||
for {
|
||||
windows.WaitForSingleObject(h, windows.INFINITE)
|
||||
dump <- new(fakeSignal)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// serve serves the ttrpc API over a unix socket at the provided path
|
||||
|
||||
Reference in New Issue
Block a user