2014-07-31 16:24:54 -04:00
|
|
|
package daemon
|
|
|
|
|
2015-07-28 14:36:38 -04:00
|
|
|
import "syscall"
|
2014-07-31 16:24:54 -04:00
|
|
|
|
|
|
|
// ContainerKill send signal to the container
|
|
|
|
// If no signal is given (sig 0), then Kill with SIGKILL and wait
|
|
|
|
// for the container to exit.
|
|
|
|
// If a signal is given, then just send it to the container and return.
|
2015-04-09 14:56:47 -04:00
|
|
|
func (daemon *Daemon) ContainerKill(name string, sig uint64) error {
|
2014-12-16 18:06:35 -05:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// If no signal is passed, or SIGKILL, perform regular Kill (SIGKILL + wait())
|
|
|
|
if sig == 0 || syscall.Signal(sig) == syscall.SIGKILL {
|
|
|
|
if err := container.Kill(); err != nil {
|
2015-07-28 14:36:38 -04:00
|
|
|
return err
|
2014-07-31 16:24:54 -04:00
|
|
|
}
|
|
|
|
} else {
|
2014-12-16 18:06:35 -05:00
|
|
|
// Otherwise, just send the requested signal
|
2015-07-30 17:01:53 -04:00
|
|
|
if err := container.killSig(int(sig)); err != nil {
|
2015-07-28 14:36:38 -04:00
|
|
|
return err
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
2014-07-31 16:24:54 -04:00
|
|
|
}
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-07-31 16:24:54 -04:00
|
|
|
}
|