Browse code

Merge pull request #33335 from cpuguy83/33334_check_unset_sig

Check signal is unset before using user stopsignal

Sebastiaan van Stijn authored on 2017/06/02 06:10:16
Showing 2 changed files
... ...
@@ -69,7 +69,7 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
69 69
 		return errNotRunning{container.ID}
70 70
 	}
71 71
 
72
-	if container.Config.StopSignal != "" {
72
+	if container.Config.StopSignal != "" && syscall.Signal(sig) != syscall.SIGKILL {
73 73
 		containerStopSignal, err := signal.ParseSignal(container.Config.StopSignal)
74 74
 		if err != nil {
75 75
 			return err
... ...
@@ -1933,3 +1933,18 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
1933 1933
 		}
1934 1934
 	}
1935 1935
 }
1936
+
1937
+// Regression test for #33334
1938
+// Makes sure that when a container which has a custom stop signal + restart=always
1939
+// gets killed (with SIGKILL) by the kill API, that the restart policy is cancelled.
1940
+func (s *DockerSuite) TestContainerKillCustomStopSignal(c *check.C) {
1941
+	id := strings.TrimSpace(runSleepingContainer(c, "--stop-signal=SIGTERM", "--restart=always"))
1942
+	res, _, err := request.Post("/containers/" + id + "/kill")
1943
+	c.Assert(err, checker.IsNil)
1944
+	defer res.Body.Close()
1945
+
1946
+	b, err := ioutil.ReadAll(res.Body)
1947
+	c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent, check.Commentf(string(b)))
1948
+	err = waitInspect(id, "{{.State.Running}} {{.State.Restarting}}", "false false", 30*time.Second)
1949
+	c.Assert(err, checker.IsNil)
1950
+}