Skip to content

Commit 37347ad

Browse files
Merge pull request #3258 from umohnani8/1.15-sig
[1.15] Pass down the integer value of the stop signal
2 parents 02115c9 + 24a29f0 commit 37347ad

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

oci/container.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"strconv"
89
"strings"
910
"sync"
1011
"syscall"
@@ -21,7 +22,7 @@ import (
2122
)
2223

2324
const (
24-
defaultStopSignal = "TERM"
25+
defaultStopSignal = "15"
2526
defaultStopSignalInt = 15
2627
)
2728

@@ -131,11 +132,13 @@ func (c *Container) GetStopSignal() string {
131132
return defaultStopSignal
132133
}
133134
cleanSignal := strings.TrimPrefix(strings.ToUpper(c.stopSignal), "SIG")
134-
_, ok := signal.SignalMap[cleanSignal]
135+
val, ok := signal.SignalMap[cleanSignal]
135136
if !ok {
136137
return defaultStopSignal
137138
}
138-
return cleanSignal
139+
// return the stop signal in the form of its int converted to a string
140+
// i.e stop signal 34 is returned as "34" to avoid back and forth conversion
141+
return strconv.Itoa(int(val))
139142
}
140143

141144
// StopSignal returns the container's own stop signal configured from

oci/container_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _ = t.Describe("Container", func() {
4545
Expect(sut.StatePath()).To(Equal("dir/state.json"))
4646
Expect(sut.Metadata()).To(Equal(&pb.ContainerMetadata{}))
4747
Expect(sut.StateNoLock().Version).To(BeEmpty())
48-
Expect(sut.GetStopSignal()).To(Equal("TERM"))
48+
Expect(sut.GetStopSignal()).To(Equal("15"))
4949
Expect(sut.CreatedAt().UnixNano()).
5050
To(BeNumerically("<", time.Now().UnixNano()))
5151
})
@@ -150,7 +150,7 @@ var _ = t.Describe("Container", func() {
150150
signal := container.GetStopSignal()
151151

152152
// Then
153-
Expect(signal).To(Equal("TERM"))
153+
Expect(signal).To(Equal("15"))
154154
})
155155

156156
It("should succeed get NetNsPath if not provided", func() {
@@ -201,7 +201,7 @@ var _ = t.Describe("Container", func() {
201201
signal := container.GetStopSignal()
202202

203203
// Then
204-
Expect(signal).To(Equal("TRAP"))
204+
Expect(signal).To(Equal("5"))
205205
})
206206

207207
It("should succeed to get the state from disk", func() {

oci/kill.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import (
44
"syscall"
55

66
"github.com/docker/docker/pkg/signal"
7-
"github.com/pkg/errors"
87
)
98

10-
// Reverse lookup signal string from its map
11-
func findStringInSignalMap(killSignal syscall.Signal) (string, error) {
12-
for k, v := range signal.SignalMap {
9+
// Check if killSignal exists in the signal map
10+
func inSignalMap(killSignal syscall.Signal) bool {
11+
for _, v := range signal.SignalMap {
1312
if v == killSignal {
14-
return k, nil
13+
return true
1514
}
1615
}
17-
return "", errors.Errorf("unable to convert signal to string")
16+
return false
1817

1918
}

oci/runtime_oci.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,13 +752,11 @@ func (r *runtimeOCI) SignalContainer(c *Container, sig syscall.Signal) error {
752752
c.opLock.Lock()
753753
defer c.opLock.Unlock()
754754

755-
signalString, err := findStringInSignalMap(sig)
756-
if err != nil {
757-
return err
755+
if !inSignalMap(sig) {
756+
return errors.Errorf("unable to find %s in the signal map", sig.String())
758757
}
759758

760-
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path,
761-
rootFlag, r.root, "kill", c.ID(), signalString)
759+
return utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "kill", c.ID(), strconv.Itoa(int(sig)))
762760
}
763761

764762
// AttachContainer attaches IO to a running container.

0 commit comments

Comments
 (0)