mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Allow "SIG" prefix on signal names in docker kill
("SIGKILL", etc)
This way, we can use both `docker kill -s INT some_container` and `docker kill -s SIGINT some_container` and both will do nice things for us. :) Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)
This commit is contained in:
parent
f6f059d99a
commit
4cb602afa0
2 changed files with 11 additions and 2 deletions
|
@ -1129,8 +1129,13 @@ func TestCmdKill(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(t, "SIGUSR2 timed out", 2*time.Second, func() {
|
setTimeout(t, "SIGUSR2 timed out", 2*time.Second, func() {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
if err := cli2.CmdKill("--signal=USR2", container.ID); err != nil {
|
sig := "USR2"
|
||||||
|
if i%2 != 0 {
|
||||||
|
// Swap to testing "SIGUSR2" for every odd iteration
|
||||||
|
sig = "SIGUSR2"
|
||||||
|
}
|
||||||
|
if err := cli2.CmdKill("--signal="+sig, container.ID); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := expectPipe("SIGUSR2", stdout); err != nil {
|
if err := expectPipe("SIGUSR2", stdout); err != nil {
|
||||||
|
|
|
@ -144,6 +144,10 @@ func (srv *Server) ContainerKill(job *engine.Job) engine.Status {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// The signal is not a number, treat it as a string
|
// The signal is not a number, treat it as a string
|
||||||
sig = uint64(signal.SignalMap[job.Args[1]])
|
sig = uint64(signal.SignalMap[job.Args[1]])
|
||||||
|
if sig == 0 && strings.HasPrefix(job.Args[1], "SIG") {
|
||||||
|
// If signal is prefixed with SIG, try with it stripped (ie, "SIGKILL", etc)
|
||||||
|
sig = uint64(signal.SignalMap[job.Args[1][3:]])
|
||||||
|
}
|
||||||
if sig == 0 {
|
if sig == 0 {
|
||||||
return job.Errorf("Invalid signal: %s", job.Args[1])
|
return job.Errorf("Invalid signal: %s", job.Args[1])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue