2014-07-31 16:24:54 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-03-25 03:44:12 -04:00
|
|
|
"fmt"
|
2014-07-31 16:24:54 -04:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("Cannot kill container %s: %s", name, err)
|
2014-07-31 16:24:54 -04:00
|
|
|
}
|
|
|
|
} else {
|
2014-12-16 18:06:35 -05:00
|
|
|
// Otherwise, just send the requested signal
|
|
|
|
if err := container.KillSig(int(sig)); err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("Cannot kill container %s: %s", name, 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
|
|
|
}
|