Skip to content

Commit 5dec27b

Browse files
committed
ctr: exec handle pty resize after Start
Handle initial pty resize after the exec process has started and the pty is available, consistent with the behavior of ctr run. Signed-off-by: Samuel Karp <[email protected]>
1 parent b9378b4 commit 5dec27b

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

cmd/ctr/commands/tasks/exec.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,31 @@ var execCommand = cli.Command{
117117
con console.Console
118118
)
119119

120-
ioOpts := []cio.Opt{cio.WithFIFODir(context.String("fifo-dir"))}
121-
if tty {
120+
fifoDir := context.String("fifo-dir")
121+
logURI := context.String("log-uri")
122+
ioOpts := []cio.Opt{cio.WithFIFODir(fifoDir)}
123+
switch {
124+
case tty && logURI != "":
125+
return errors.New("can't use log-uri with tty")
126+
case logURI != "" && fifoDir != "":
127+
return errors.New("can't use log-uri with fifo-dir")
128+
129+
case tty:
122130
con = console.Current()
123131
defer con.Reset()
124132
if err := con.SetRaw(); err != nil {
125133
return err
126134
}
127135
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
128-
} else if logURI := context.String("log-uri"); logURI != "" {
136+
137+
case logURI != "":
129138
uri, err := url.Parse(logURI)
130139
if err != nil {
131140
return err
132141
}
133-
134-
if dir := context.String("fifo-dir"); dir != "" {
135-
return errors.New("can't use log-uri with fifo-dir")
136-
}
137-
138-
if tty {
139-
return errors.New("can't use log-uri with tty")
140-
}
141-
142142
ioCreator = cio.LogURI(uri)
143-
} else {
143+
144+
default:
144145
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
145146
}
146147

@@ -161,23 +162,20 @@ var execCommand = cli.Command{
161162
return err
162163
}
163164

164-
if !detach {
165-
if tty {
166-
if err := HandleConsoleResize(ctx, process, con); err != nil {
167-
logrus.WithError(err).Error("console resize")
168-
}
169-
} else {
170-
sigc := commands.ForwardAllSignals(ctx, process)
171-
defer commands.StopCatch(sigc)
172-
}
173-
}
174-
175165
if err := process.Start(ctx); err != nil {
176166
return err
177167
}
178168
if detach {
179169
return nil
180170
}
171+
if tty {
172+
if err := HandleConsoleResize(ctx, process, con); err != nil {
173+
logrus.WithError(err).Error("console resize")
174+
}
175+
} else {
176+
sigc := commands.ForwardAllSignals(ctx, process)
177+
defer commands.StopCatch(sigc)
178+
}
181179
status := <-statusC
182180
code, _, err := status.Result()
183181
if err != nil {

0 commit comments

Comments
 (0)