Skip to content

Commit

Permalink
Merge pull request #1841 from thaJeztah/fix_sig_proxy
Browse files Browse the repository at this point in the history
Do not disable sig-proxy when using a TTY
  • Loading branch information
silvin-lubecki authored Jun 25, 2019
2 parents 7c4eddc + 7cf1a8d commit bd4206f
Show file tree
Hide file tree
Showing 31 changed files with 850 additions and 5 deletions.
5 changes: 0 additions & 5 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
config.StdinOnce = false
}

// Disable sigProxy when in TTY mode
if config.Tty {
opts.sigProxy = false
}

// Telling the Windows daemon the initial size of the tty during start makes
// a far better user experience rather than relying on subsequent resizes
// to cause things to catch up.
Expand Down
56 changes: 56 additions & 0 deletions e2e/container/proxy_signal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package container

import (
"os/exec"
"strings"
"syscall"
"testing"
"time"

"github.com/docker/cli/e2e/internal/fixtures"
"github.com/kr/pty"
"gotest.tools/assert"
"gotest.tools/icmd"
"gotest.tools/poll"
)

// TestSigProxyWithTTY tests that killing the docker CLI forwards the signal to
// the container, and kills the container's process. Test-case for moby/moby#28872
func TestSigProxyWithTTY(t *testing.T) {
_, tty, err := pty.Open()
assert.NilError(t, err, "could not open pty")
defer func() { _ = tty.Close() }()

containerName := "repro-28872"
cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", containerName, fixtures.BusyboxImage, "sleep", "30")
cmd.Stdin = tty
cmd.Stdout = tty
cmd.Stderr = tty

err = cmd.Start()
out, _ := cmd.CombinedOutput()
assert.NilError(t, err, "failed to start container: %s", out)
defer icmd.RunCommand("docker", "container", "rm", "-f", containerName)

poll.WaitOn(t, containerExistsWithStatus(t, containerName, "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))

pid := cmd.Process.Pid
t.Logf("terminating PID %d", pid)
err = syscall.Kill(pid, syscall.SIGTERM)
assert.NilError(t, err)

poll.WaitOn(t, containerExistsWithStatus(t, containerName, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
}

func containerExistsWithStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result {
return func(poll.LogT) poll.Result {
result := icmd.RunCommand("docker", "inspect", "-f", "{{ .State.Status }}", containerID)
// ignore initial failures as the container may not yet exist (i.e., don't result.Assert(t, icmd.Success))

actual := strings.TrimSpace(result.Stdout())
if actual == status {
return poll.Success()
}
return poll.Continue("expected status %s != %s", status, actual)
}
}
1 change: 1 addition & 0 deletions vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce8
github.com/jaguilar/vt100 ad4c4a5743050fb7f88ce968dca9422f72a0e3f2 git://github.com/tonistiigi/vt100.git
github.com/json-iterator/go 0ff49de124c6f76f8494e194af75bde0f1a49a29 # 1.1.6
github.com/konsorten/go-windows-terminal-sequences f55edac94c9bbba5d6182a4be46d86a2c9b5b50e # v1.0.2
github.com/kr/pty 521317be5ebc228a0f0ede099fa2a0b5ece22e49 # v1.1.4
github.com/mattn/go-shellwords a72fbe27a1b0ed0df2f02754945044ce1456608b # v1.0.5
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1
github.com/Microsoft/go-winio 84b4ab48a50763fe7b3abcef38e5205c12027fac
Expand Down
23 changes: 23 additions & 0 deletions vendor/github.com/kr/pty/License

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions vendor/github.com/kr/pty/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vendor/github.com/kr/pty/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/kr/pty/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/github.com/kr/pty/ioctl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions vendor/github.com/kr/pty/ioctl_bsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions vendor/github.com/kr/pty/pty_darwin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bd4206f

Please sign in to comment.