kill.go 807 B

12345678910111213141516171819202122232425262728293031
  1. package daemon
  2. import (
  3. "syscall"
  4. "github.com/docker/docker/context"
  5. )
  6. // ContainerKill send signal to the container
  7. // If no signal is given (sig 0), then Kill with SIGKILL and wait
  8. // for the container to exit.
  9. // If a signal is given, then just send it to the container and return.
  10. func (daemon *Daemon) ContainerKill(ctx context.Context, name string, sig uint64) error {
  11. container, err := daemon.Get(ctx, name)
  12. if err != nil {
  13. return err
  14. }
  15. // If no signal is passed, or SIGKILL, perform regular Kill (SIGKILL + wait())
  16. if sig == 0 || syscall.Signal(sig) == syscall.SIGKILL {
  17. if err := container.Kill(ctx); err != nil {
  18. return err
  19. }
  20. } else {
  21. // Otherwise, just send the requested signal
  22. if err := container.killSig(ctx, int(sig)); err != nil {
  23. return err
  24. }
  25. }
  26. return nil
  27. }