Skip to content

Commit b9378b4

Browse files
committed
ctr: exec setup IO with console
Use cio.WithStreams with explicit console device when --tty is passed, consistent with how ctr run behaves. Signed-off-by: Samuel Karp <[email protected]>
1 parent a0efc54 commit b9378b4

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

cmd/ctr/commands/tasks/exec.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,18 @@ var execCommand = cli.Command{
114114
stdinC = &stdinCloser{
115115
stdin: os.Stdin,
116116
}
117+
con console.Console
117118
)
118119

119-
if logURI := context.String("log-uri"); logURI != "" {
120+
ioOpts := []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
121+
if tty {
122+
con = console.Current()
123+
defer con.Reset()
124+
if err := con.SetRaw(); err != nil {
125+
return err
126+
}
127+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
128+
} else if logURI := context.String("log-uri"); logURI != "" {
120129
uri, err := url.Parse(logURI)
121130
if err != nil {
122131
return err
@@ -132,11 +141,7 @@ var execCommand = cli.Command{
132141

133142
ioCreator = cio.LogURI(uri)
134143
} else {
135-
cioOpts := []cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr), cio.WithFIFODir(context.String("fifo-dir"))}
136-
if tty {
137-
cioOpts = append(cioOpts, cio.WithTerminal)
138-
}
139-
ioCreator = cio.NewCreator(cioOpts...)
144+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
140145
}
141146

142147
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
@@ -156,14 +161,6 @@ var execCommand = cli.Command{
156161
return err
157162
}
158163

159-
var con console.Console
160-
if tty {
161-
con = console.Current()
162-
defer con.Reset()
163-
if err := con.SetRaw(); err != nil {
164-
return err
165-
}
166-
}
167164
if !detach {
168165
if tty {
169166
if err := HandleConsoleResize(ctx, process, con); err != nil {

0 commit comments

Comments
 (0)