Skip to content

Commit 6cfb498

Browse files
committed
tty: remove remaining usages of docker/pkg/term
This removes usages of docker/pkg/term to set raw terminal, handle interrupt and restore the terminal, and instead use containerd/console and handle interrupt ourselves. Signed-off-by: Daniel Dao <[email protected]>
1 parent 1439022 commit 6cfb498

File tree

10 files changed

+20
-1795
lines changed

10 files changed

+20
-1795
lines changed

tty.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"os/signal"
910
"sync"
1011

1112
"github.com/containerd/console"
12-
"github.com/docker/docker/pkg/term"
1313
"github.com/opencontainers/runc/libcontainer"
1414
"github.com/opencontainers/runc/libcontainer/utils"
1515
)
1616

1717
type tty struct {
1818
epoller *console.Epoller
1919
console *console.EpollConsole
20-
state *term.State
20+
stdin console.Console
2121
closers []io.Closer
2222
postStart []io.Closer
2323
wg sync.WaitGroup
@@ -93,19 +93,31 @@ func (t *tty) recvtty(process *libcontainer.Process, socket *os.File) error {
9393
t.wg.Add(1)
9494
go t.copyIO(os.Stdout, epollConsole)
9595

96-
// TODO: perhaps migrate to console.SetRaw later. Need to handle interrupt
97-
// ourselves though
98-
state, err := term.SetRawTerminal(os.Stdin.Fd())
96+
// set raw mode to stdin and also handle interrupt
97+
stdin, err := console.ConsoleFromFile(os.Stdin)
9998
if err != nil {
99+
return err
100+
}
101+
if err := stdin.SetRaw(); err != nil {
100102
return fmt.Errorf("failed to set the terminal from the stdin: %v", err)
101103
}
104+
go handleInterrupt(stdin)
105+
102106
t.epoller = epoller
103-
t.state = state
107+
t.stdin = stdin
104108
t.console = epollConsole
105109
t.closers = []io.Closer{epollConsole}
106110
return nil
107111
}
108112

113+
func handleInterrupt(c console.Console) {
114+
sigchan := make(chan os.Signal, 1)
115+
signal.Notify(sigchan, os.Interrupt)
116+
<-sigchan
117+
c.Reset()
118+
os.Exit(0)
119+
}
120+
109121
func (t *tty) waitConsole() error {
110122
if t.consoleC != nil {
111123
return <-t.consoleC
@@ -138,8 +150,8 @@ func (t *tty) Close() error {
138150
for _, c := range t.closers {
139151
c.Close()
140152
}
141-
if t.state != nil {
142-
term.RestoreTerminal(os.Stdin.Fd(), t.state)
153+
if t.stdin != nil {
154+
t.stdin.Reset()
143155
}
144156
return nil
145157
}

vendor/github.com/docker/docker/pkg/term/tc_linux_cgo.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/term/tc_other.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/term/term.go

Lines changed: 0 additions & 118 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/term/term_windows.go

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)