2014-07-31 16:24:54 -04:00
|
|
|
package daemon
|
|
|
|
|
2015-10-12 19:34:03 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/signal"
|
|
|
|
)
|
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-09-29 13:51:40 -04:00
|
|
|
func (daemon *Daemon) ContainerKill(name string, sig uint64) error {
|
|
|
|
container, err := daemon.Get(name)
|
2014-12-16 18:06:35 -05:00
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-12-16 18:06:35 -05:00
|
|
|
}
|
|
|
|
|
2015-10-12 19:34:03 -04:00
|
|
|
if sig != 0 && !signal.ValidSignalForPlatform(syscall.Signal(sig)) {
|
|
|
|
return fmt.Errorf("The %s daemon does not support signal %d", runtime.GOOS, sig)
|
|
|
|
}
|
|
|
|
|
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 {
|
2015-09-29 13:51:40 -04:00
|
|
|
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-09-29 13:51:40 -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
|
|
|
}
|