Merge pull request #5527 from samuelkarp/freebsd-ctr-exec

ctr: make exec pty behavior consistent with run
This commit is contained in:
Phil Estes 2021-05-25 13:24:10 -04:00 committed by GitHub
commit 0a92694e0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,29 +114,35 @@ var execCommand = cli.Command{
stdinC = &stdinCloser{ stdinC = &stdinCloser{
stdin: os.Stdin, stdin: os.Stdin,
} }
con console.Console
) )
if logURI := context.String("log-uri"); logURI != "" { fifoDir := context.String("fifo-dir")
logURI := context.String("log-uri")
ioOpts := []cio.Opt{cio.WithFIFODir(fifoDir)}
switch {
case tty && logURI != "":
return errors.New("can't use log-uri with tty")
case logURI != "" && fifoDir != "":
return errors.New("can't use log-uri with fifo-dir")
case tty:
con = console.Current()
defer con.Reset()
if err := con.SetRaw(); err != nil {
return err
}
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
case logURI != "":
uri, err := url.Parse(logURI) uri, err := url.Parse(logURI)
if err != nil { if err != nil {
return err return err
} }
if dir := context.String("fifo-dir"); dir != "" {
return errors.New("can't use log-uri with fifo-dir")
}
if tty {
return errors.New("can't use log-uri with tty")
}
ioCreator = cio.LogURI(uri) ioCreator = cio.LogURI(uri)
} else {
cioOpts := []cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr), cio.WithFIFODir(context.String("fifo-dir"))} default:
if tty { ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
cioOpts = append(cioOpts, cio.WithTerminal)
}
ioCreator = cio.NewCreator(cioOpts...)
} }
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator) process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
@ -156,15 +162,12 @@ var execCommand = cli.Command{
return err return err
} }
var con console.Console if err := process.Start(ctx); err != nil {
if tty {
con = console.Current()
defer con.Reset()
if err := con.SetRaw(); err != nil {
return err return err
} }
if detach {
return nil
} }
if !detach {
if tty { if tty {
if err := HandleConsoleResize(ctx, process, con); err != nil { if err := HandleConsoleResize(ctx, process, con); err != nil {
logrus.WithError(err).Error("console resize") logrus.WithError(err).Error("console resize")
@ -173,14 +176,6 @@ var execCommand = cli.Command{
sigc := commands.ForwardAllSignals(ctx, process) sigc := commands.ForwardAllSignals(ctx, process)
defer commands.StopCatch(sigc) defer commands.StopCatch(sigc)
} }
}
if err := process.Start(ctx); err != nil {
return err
}
if detach {
return nil
}
status := <-statusC status := <-statusC
code, _, err := status.Result() code, _, err := status.Result()
if err != nil { if err != nil {