Skip to content

Commit 248ff06

Browse files
authored
Merge pull request #2562 from crosbymichael/console
Fix windows interactive consoles
2 parents 53a8c94 + 4f644db commit 248ff06

7 files changed

Lines changed: 100 additions & 64 deletions

File tree

cio/io_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (*cio, error) {
9999
}()
100100
}
101101

102-
if !fifos.Terminal && fifos.Stderr != "" {
102+
if fifos.Stderr != "" {
103103
l, err := winio.ListenPipe(fifos.Stderr, nil)
104104
if err != nil {
105105
return nil, errors.Wrapf(err, "failed to create stderr pipe %s", fifos.Stderr)

cmd/ctr/commands/run/run.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,17 @@ var Command = cli.Command{
135135
if context.Bool("rm") && !detach {
136136
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
137137
}
138+
var con console.Console
139+
if tty {
140+
con = console.Current()
141+
defer con.Reset()
142+
if err := con.SetRaw(); err != nil {
143+
return err
144+
}
145+
}
138146
opts := getNewTaskOpts(context)
139147
ioOpts := []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
140-
task, err := tasks.NewTask(ctx, client, container, context.String("checkpoint"), tty, context.Bool("null-io"), ioOpts, opts...)
148+
task, err := tasks.NewTask(ctx, client, container, context.String("checkpoint"), con, context.Bool("null-io"), ioOpts, opts...)
141149
if err != nil {
142150
return err
143151
}
@@ -153,14 +161,6 @@ var Command = cli.Command{
153161
return err
154162
}
155163
}
156-
var con console.Console
157-
if tty {
158-
con = console.Current()
159-
defer con.Reset()
160-
if err := con.SetRaw(); err != nil {
161-
return err
162-
}
163-
}
164164
if err := task.Start(ctx); err != nil {
165165
return err
166166
}

cmd/ctr/commands/tasks/start.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,21 @@ var startCommand = cli.Command{
6565
if err != nil {
6666
return err
6767
}
68-
6968
var (
7069
tty = spec.Process.Terminal
7170
opts = getNewTaskOpts(context)
7271
ioOpts = []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
7372
)
74-
task, err := NewTask(ctx, client, container, "", tty, context.Bool("null-io"), ioOpts, opts...)
73+
var con console.Console
74+
if tty {
75+
con = console.Current()
76+
defer con.Reset()
77+
if err := con.SetRaw(); err != nil {
78+
return err
79+
}
80+
}
81+
82+
task, err := NewTask(ctx, client, container, "", con, context.Bool("null-io"), ioOpts, opts...)
7583
if err != nil {
7684
return err
7785
}
@@ -86,14 +94,6 @@ var startCommand = cli.Command{
8694
return err
8795
}
8896

89-
var con console.Console
90-
if tty {
91-
con = console.Current()
92-
defer con.Reset()
93-
if err := con.SetRaw(); err != nil {
94-
return err
95-
}
96-
}
9797
if err := task.Start(ctx); err != nil {
9898
return err
9999
}

cmd/ctr/commands/tasks/tasks_unix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
6767
}
6868

6969
// NewTask creates a new task
70-
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
70+
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, checkpoint string, con console.Console, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
7171
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...)
7272
if checkpoint != "" {
7373
im, err := client.GetImage(ctx, checkpoint)
@@ -77,11 +77,11 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
7777
opts = append(opts, containerd.WithTaskCheckpoint(im))
7878
}
7979
ioCreator := stdio
80-
if tty {
81-
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
80+
if con != nil {
81+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
8282
}
8383
if nullIO {
84-
if tty {
84+
if con != nil {
8585
return nil, errors.New("tty and null-io cannot be used together")
8686
}
8787
ioCreator = cio.NullIO

cmd/ctr/commands/tasks/tasks_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
5858
}
5959

6060
// NewTask creates a new task
61-
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
61+
func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, con console.Console, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) {
6262
var ioCreator cio.Creator
63-
if tty {
63+
if con != nil {
6464
if nullIO {
6565
return nil, errors.New("tty and null-io cannot be used together")
6666
}
67-
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...)
67+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, con), cio.WithTerminal}, ioOpts...)...)
6868
} else if nullIO {
6969
ioCreator = cio.NullIO
7070
} else {

vendor.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
github.com/containerd/go-runc 808e8444ac4633a8e5eb7314fc6b5d27051727dd
2-
github.com/containerd/console 4d8a41f4ce5b9bae77c41786ea2458330f43f081
2+
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
33
github.com/containerd/cgroups 5e610833b72089b37d0e615de9a92dfc043757c2
44
github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40
55
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c

vendor/github.com/containerd/console/console_windows.go

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

0 commit comments

Comments
 (0)