Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 0dabf1e

Browse files
authored
Merge pull request #2177 from thaJeztah/19.03_backport_fix_sig_proxy
[19.03 backport] Do not disable sig-proxy when using a TTY Upstream-commit: 99c5edceb48d64c1aa5d09b8c9c499d431d98bb9 Component: cli
2 parents 76c903b + 30a660e commit 0dabf1e

31 files changed

Lines changed: 844 additions & 5 deletions

components/cli/cli/command/container/run.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
115115
config.StdinOnce = false
116116
}
117117

118-
// Disable sigProxy when in TTY mode
119-
if config.Tty {
120-
opts.sigProxy = false
121-
}
122-
123118
// Telling the Windows daemon the initial size of the tty during start makes
124119
// a far better user experience rather than relying on subsequent resizes
125120
// to cause things to catch up.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package container
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
"syscall"
7+
"testing"
8+
"time"
9+
10+
"github.com/docker/cli/e2e/internal/fixtures"
11+
"github.com/kr/pty"
12+
"gotest.tools/assert"
13+
"gotest.tools/icmd"
14+
"gotest.tools/poll"
15+
)
16+
17+
// TestSigProxyWithTTY tests that killing the docker CLI forwards the signal to
18+
// the container, and kills the container's process. Test-case for moby/moby#28872
19+
func TestSigProxyWithTTY(t *testing.T) {
20+
cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", t.Name(), fixtures.BusyboxImage, "sleep", "30")
21+
p, err := pty.Start(cmd)
22+
defer func() {
23+
_ = cmd.Wait()
24+
_ = p.Close()
25+
}()
26+
assert.NilError(t, err, "failed to start container")
27+
defer icmd.RunCommand("docker", "container", "rm", "-f", t.Name())
28+
29+
poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
30+
31+
pid := cmd.Process.Pid
32+
t.Logf("terminating PID %d", pid)
33+
err = syscall.Kill(pid, syscall.SIGTERM)
34+
assert.NilError(t, err)
35+
36+
poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
37+
}
38+
39+
func containerExistsWithStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result {
40+
return func(poll.LogT) poll.Result {
41+
result := icmd.RunCommand("docker", "inspect", "-f", "{{ .State.Status }}", containerID)
42+
// ignore initial failures as the container may not yet exist (i.e., don't result.Assert(t, icmd.Success))
43+
44+
actual := strings.TrimSpace(result.Stdout())
45+
if actual == status {
46+
return poll.Success()
47+
}
48+
return poll.Continue("expected status %s != %s", status, actual)
49+
}
50+
}

components/cli/vendor.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce8
4646
github.com/jaguilar/vt100 ad4c4a5743050fb7f88ce968dca9422f72a0e3f2 git://github.com/tonistiigi/vt100.git
4747
github.com/json-iterator/go 0ff49de124c6f76f8494e194af75bde0f1a49a29 # 1.1.6
4848
github.com/konsorten/go-windows-terminal-sequences f55edac94c9bbba5d6182a4be46d86a2c9b5b50e # v1.0.2
49+
github.com/kr/pty 521317be5ebc228a0f0ede099fa2a0b5ece22e49 # v1.1.4
4950
github.com/mattn/go-shellwords a72fbe27a1b0ed0df2f02754945044ce1456608b # v1.0.5
5051
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1
5152
github.com/Microsoft/go-winio 84b4ab48a50763fe7b3abcef38e5205c12027fac

components/cli/vendor/github.com/kr/pty/License

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/README.md

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/doc.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/go.mod

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/ioctl.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/ioctl_bsd.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/pty_darwin.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)