Skip to content

Commit 0a92694

Browse files
authored
Merge pull request #5527 from samuelkarp/freebsd-ctr-exec
ctr: make exec pty behavior consistent with run
2 parents c0794c0 + 5dec27b commit 0a92694

1 file changed

Lines changed: 30 additions & 35 deletions

File tree

cmd/ctr/commands/tasks/exec.go

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,35 @@ 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-
uri, err := url.Parse(logURI)
121-
if err != nil {
122-
return err
123-
}
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")
124128

125-
if dir := context.String("fifo-dir"); dir != "" {
126-
return errors.New("can't use log-uri with fifo-dir")
129+
case tty:
130+
con = console.Current()
131+
defer con.Reset()
132+
if err := con.SetRaw(); err != nil {
133+
return err
127134
}
135+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
128136

129-
if tty {
130-
return errors.New("can't use log-uri with tty")
137+
case logURI != "":
138+
uri, err := url.Parse(logURI)
139+
if err != nil {
140+
return err
131141
}
132-
133142
ioCreator = cio.LogURI(uri)
134-
} 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...)
143+
144+
default:
145+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
140146
}
141147

142148
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
@@ -156,31 +162,20 @@ var execCommand = cli.Command{
156162
return err
157163
}
158164

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-
}
167-
if !detach {
168-
if tty {
169-
if err := HandleConsoleResize(ctx, process, con); err != nil {
170-
logrus.WithError(err).Error("console resize")
171-
}
172-
} else {
173-
sigc := commands.ForwardAllSignals(ctx, process)
174-
defer commands.StopCatch(sigc)
175-
}
176-
}
177-
178165
if err := process.Start(ctx); err != nil {
179166
return err
180167
}
181168
if detach {
182169
return nil
183170
}
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+
}
184179
status := <-statusC
185180
code, _, err := status.Result()
186181
if err != nil {

0 commit comments

Comments
 (0)