terminatekill.go 1.4 KB

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