From 8148ab6c9050f654948db6c75736b0c2f8fdd2a1 Mon Sep 17 00:00:00 2001 From: John Howard Date: Wed, 1 Jul 2015 10:50:33 -0700 Subject: [PATCH] Added terminatecomputesystem Signed-off-by: John Howard --- hcsshim.go | 1 + terminatecomputesystem.go | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 terminatecomputesystem.go diff --git a/hcsshim.go b/hcsshim.go index 1ac0aa5212..3db9beaf3d 100644 --- a/hcsshim.go +++ b/hcsshim.go @@ -21,6 +21,7 @@ const ( procCreateProcessInComputeSystem = "CreateProcessInComputeSystem" procWaitForProcessInComputeSystem = "WaitForProcessInComputeSystem" procShutdownComputeSystem = "ShutdownComputeSystem" + procTerminateComputeSystem = "TerminateComputeSystem" procTerminateProcessInComputeSystem = "TerminateProcessInComputeSystem" procResizeConsoleInComputeSystem = "ResizeConsoleInComputeSystem" diff --git a/terminatecomputesystem.go b/terminatecomputesystem.go new file mode 100644 index 0000000000..a51d829642 --- /dev/null +++ b/terminatecomputesystem.go @@ -0,0 +1,49 @@ +package hcsshim + +import ( + "fmt" + "syscall" + "unsafe" + + "github.com/Sirupsen/logrus" +) + +// TerminateComputeSystem force terminates a container +func TerminateComputeSystem(id string) error { + + var title = "HCSShim::TerminateComputeSystem" + logrus.Debugf(title+" id=%s", id) + + // Load the DLL and get a handle to the procedure we need + dll, proc, err := loadAndFind(procTerminateComputeSystem) + if dll != nil { + defer dll.Release() + } + if err != nil { + return err + } + + // Convert id to uint16 pointers for calling the procedure + idp, err := syscall.UTF16PtrFromString(id) + if err != nil { + err = fmt.Errorf(title+" - Failed conversion of id %s to pointer %s", id, err) + logrus.Error(err) + return err + } + + timeout := uint32(0xffffffff) + + // Call the procedure itself. + r1, _, err := proc.Call( + uintptr(unsafe.Pointer(idp)), uintptr(timeout)) + + use(unsafe.Pointer(idp)) + + if r1 != 0 { + err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s id=%s", r1, syscall.Errno(r1), id) + return syscall.Errno(r1) + } + + logrus.Debugf(title+" - succeeded id=%s", id) + return nil +}