Remove Job from docker kill

Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: 3cb751906a8a0397dcf57d8fca97c0e9c0c418e8
Component: engine
This commit is contained in:
Doug Davis
2015-04-09 11:56:47 -07:00
parent 146dc925a6
commit 4ef2fa0ccf
5 changed files with 29 additions and 41 deletions

View File

@ -2,43 +2,14 @@ package daemon
import (
"fmt"
"strconv"
"strings"
"syscall"
"github.com/docker/docker/engine"
"github.com/docker/docker/pkg/signal"
)
// 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.
func (daemon *Daemon) ContainerKill(job *engine.Job) error {
if n := len(job.Args); n < 1 || n > 2 {
return fmt.Errorf("Usage: %s CONTAINER [SIGNAL]", job.Name)
}
var (
name = job.Args[0]
sig uint64
err error
)
// If we have a signal, look at it. Otherwise, do nothing
if len(job.Args) == 2 && job.Args[1] != "" {
// Check if we passed the signal as a number:
// The largest legal signal is 31, so let's parse on 5 bits
sig, err = strconv.ParseUint(job.Args[1], 10, 5)
if err != nil {
// The signal is not a number, treat it as a string (either like "KILL" or like "SIGKILL")
sig = uint64(signal.SignalMap[strings.TrimPrefix(job.Args[1], "SIG")])
}
if sig == 0 {
return fmt.Errorf("Invalid signal: %s", job.Args[1])
}
}
func (daemon *Daemon) ContainerKill(name string, sig uint64) error {
container, err := daemon.Get(name)
if err != nil {
return err
@ -49,13 +20,12 @@ func (daemon *Daemon) ContainerKill(job *engine.Job) error {
if err := container.Kill(); err != nil {
return fmt.Errorf("Cannot kill container %s: %s", name, err)
}
container.LogEvent("kill")
} else {
// Otherwise, just send the requested signal
if err := container.KillSig(int(sig)); err != nil {
return fmt.Errorf("Cannot kill container %s: %s", name, err)
}
// FIXME: Add event for signals
}
container.LogEvent("kill")
return nil
}