Fix LXC stop signals
`lxc-stop` does not support sending arbitrary signals. By default, `lxc-stop -n <id>` would send `SIGPWR`. The lxc driver was always sending `lxc-stop -n <id> -k`, which always sends `SIGKILL`. In this case `lxc-start` returns an exit code of `0`, regardless of what the container actually exited with. Because of this we must send signals directly to the process when we can. Also need to set quiet mode on `lxc-start` otherwise it reports an error on `stderr` when the container exits cleanly (ie, we didn't SIGKILL it), this error is picked up in the container logs... and isn't really an error. Also cleaned up some potential races for waitblocked test. Signed-off-by: Brian Goff <cpuguy83@gmail.com> Upstream-commit: d2c4ee37c6a4114b33a915b7dae6de70e27e7965 Component: engine
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
@ -44,7 +45,7 @@ func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) {
|
||||
|
||||
// blocking wait with 0 exit code
|
||||
func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' SIGTERM; while true; do sleep 0.01; done")
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 0' TERM; while true; do sleep 0.01; done")
|
||||
containerID := strings.TrimSpace(out)
|
||||
|
||||
if err := waitRun(containerID); err != nil {
|
||||
@ -107,7 +108,7 @@ func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) {
|
||||
|
||||
// blocking wait with random exit code
|
||||
func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "trap 'exit 99' SIGTERM; while true; do sleep 0.01; done")
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "trap 'exit 99' TERM; while true; do sleep 0.01; done")
|
||||
containerID := strings.TrimSpace(out)
|
||||
if err := waitRun(containerID); err != nil {
|
||||
c.Fatal(err)
|
||||
@ -116,21 +117,34 @@ func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
chWait := make(chan string)
|
||||
chWait := make(chan error)
|
||||
waitCmd := exec.Command(dockerBinary, "wait", containerID)
|
||||
waitCmdOut := bytes.NewBuffer(nil)
|
||||
waitCmd.Stdout = waitCmdOut
|
||||
if err := waitCmd.Start(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID))
|
||||
chWait <- out
|
||||
chWait <- waitCmd.Wait()
|
||||
}()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
dockerCmd(c, "stop", containerID)
|
||||
|
||||
select {
|
||||
case status := <-chWait:
|
||||
case err := <-chWait:
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
status, err := waitCmdOut.ReadString('\n')
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
if strings.TrimSpace(status) != "99" {
|
||||
c.Fatalf("expected exit 99, got %s", status)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
waitCmd.Process.Kill()
|
||||
c.Fatal("timeout waiting for `docker wait` to exit")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user