Ensure that Streams are set to defaults for HTTP attach

If not overridden, we should use the attach configuration given
when the exec session was first created.

Also, setting streams should not conflict with a TTY - the two
are allowed together with Attach and should be allowed together
here.

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon 2020-04-15 16:17:11 -04:00 committed by Matthew Heon
parent ce56b68871
commit 4d410b7cb7

View file

@ -158,9 +158,6 @@ func (c *Container) ExecCreate(config *ExecConfig) (string, error) {
if len(config.Command) == 0 {
return "", errors.Wrapf(define.ErrInvalidArg, "must provide a non-empty command to start an exec session")
}
if config.Terminal && (config.AttachStdin || config.AttachStdout || config.AttachStderr) {
return "", errors.Wrapf(define.ErrInvalidArg, "cannot specify streams to attach to when exec session has a pseudoterminal")
}
// Verify that we are in a good state to continue
if !c.ensureState(define.ContainerStateRunning) {
@ -362,6 +359,13 @@ func (c *Container) ExecHTTPStartAndAttach(sessionID string, httpCon net.Conn, h
return err
}
if streams == nil {
streams = new(HTTPAttachStreams)
streams.Stdin = session.Config.AttachStdin
streams.Stdout = session.Config.AttachStdout
streams.Stderr = session.Config.AttachStderr
}
pid, attachChan, err := c.ociRuntime.ExecContainerHTTP(c, session.ID(), execOpts, httpCon, httpBuf, streams, cancel)
if err != nil {
return err