terminatekill.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // +build windows
  2. package windows
  3. import (
  4. "github.com/Sirupsen/logrus"
  5. "github.com/docker/docker/daemon/execdriver"
  6. "github.com/microsoft/hcsshim"
  7. )
  8. // Terminate implements the exec driver Driver interface.
  9. func (d *Driver) Terminate(p *execdriver.Command) error {
  10. logrus.Debugf("WindowsExec: Terminate() id=%s", p.ID)
  11. return kill(p.ID, p.ContainerPid)
  12. }
  13. // Kill implements the exec driver Driver interface.
  14. func (d *Driver) Kill(p *execdriver.Command, sig int) error {
  15. logrus.Debugf("WindowsExec: Kill() id=%s sig=%d", p.ID, sig)
  16. return kill(p.ID, p.ContainerPid)
  17. }
  18. func kill(id string, pid int) error {
  19. logrus.Debugln("kill() ", id, pid)
  20. var err error
  21. // Terminate Process
  22. if err = hcsshim.TerminateProcessInComputeSystem(id, uint32(pid)); err != nil {
  23. logrus.Warnf("Failed to terminate pid %d in %s", id, pid, err)
  24. // Ignore errors
  25. err = nil
  26. }
  27. if terminateMode {
  28. // Terminate the compute system
  29. if err = hcsshim.TerminateComputeSystem(id); err != nil {
  30. logrus.Errorf("Failed to terminate %s - %s", id, err)
  31. }
  32. } else {
  33. // Shutdown the compute system
  34. if err = hcsshim.ShutdownComputeSystem(id); err != nil {
  35. logrus.Errorf("Failed to shutdown %s - %s", id, err)
  36. }
  37. }
  38. return err
  39. }