Switch to bufio Reader for exec streams

There were many situations that made exec act funky with input. pipes didn't work as expected, as well as sending input before the shell opened.
Thinking about it, it seemed as though the issues were because of how os.Stdin buffers (it doesn't). Dropping this input had some weird consequences.
Instead, read from os.Stdin as bufio.Reader, allowing the input to buffer before passing it to the container.

Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
Peter Hunt
2019-10-31 10:41:26 -04:00
parent 9ba8dae0bf
commit 1df4dba0a0
5 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package libpod package libpod
import ( import (
"bufio"
"context" "context"
"io" "io"
"io/ioutil" "io/ioutil"
@ -361,7 +362,7 @@ type AttachStreams struct {
// ErrorStream will be attached to container's STDERR // ErrorStream will be attached to container's STDERR
ErrorStream io.WriteCloser ErrorStream io.WriteCloser
// InputStream will be attached to container's STDIN // InputStream will be attached to container's STDIN
InputStream io.Reader InputStream *bufio.Reader
// AttachOutput is whether to attach to STDOUT // AttachOutput is whether to attach to STDOUT
// If false, stdout will not be attached // If false, stdout will not be attached
AttachOutput bool AttachOutput bool

View File

@ -133,7 +133,9 @@ func (c *Container) runHealthCheck() (HealthCheckStatus, error) {
streams := new(AttachStreams) streams := new(AttachStreams)
streams.OutputStream = hcw streams.OutputStream = hcw
streams.ErrorStream = hcw streams.ErrorStream = hcw
streams.InputStream = os.Stdin
streams.InputStream = bufio.NewReader(os.Stdin)
streams.AttachOutput = true streams.AttachOutput = true
streams.AttachError = true streams.AttachError = true
streams.AttachInput = true streams.AttachInput = true

View File

@ -891,7 +891,7 @@ func (r *LocalRuntime) execPS(c *libpod.Container, args []string) ([]string, err
streams := new(libpod.AttachStreams) streams := new(libpod.AttachStreams)
streams.OutputStream = wPipe streams.OutputStream = wPipe
streams.ErrorStream = wPipe streams.ErrorStream = wPipe
streams.InputStream = os.Stdin streams.InputStream = bufio.NewReader(os.Stdin)
streams.AttachOutput = true streams.AttachOutput = true
streams.AttachError = true streams.AttachError = true
streams.AttachInput = true streams.AttachInput = true
@ -969,7 +969,7 @@ func (r *LocalRuntime) ExecContainer(ctx context.Context, cli *cliconfig.ExecVal
streams.OutputStream = os.Stdout streams.OutputStream = os.Stdout
streams.ErrorStream = os.Stderr streams.ErrorStream = os.Stderr
if cli.Interactive { if cli.Interactive {
streams.InputStream = os.Stdin streams.InputStream = bufio.NewReader(os.Stdin)
streams.AttachInput = true streams.AttachInput = true
} }
streams.AttachOutput = true streams.AttachOutput = true

View File

@ -1,6 +1,7 @@
package adapter package adapter
import ( import (
"bufio"
"context" "context"
"fmt" "fmt"
"os" "os"
@ -61,7 +62,7 @@ func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr,
streams := new(libpod.AttachStreams) streams := new(libpod.AttachStreams)
streams.OutputStream = stdout streams.OutputStream = stdout
streams.ErrorStream = stderr streams.ErrorStream = stderr
streams.InputStream = stdin streams.InputStream = bufio.NewReader(stdin)
streams.AttachOutput = true streams.AttachOutput = true
streams.AttachError = true streams.AttachError = true
streams.AttachInput = true streams.AttachInput = true

View File

@ -32,7 +32,7 @@ func setupStreams(call iopodman.VarlinkCall) (*bufio.Reader, *bufio.Writer, *io.
streams := libpod.AttachStreams{ streams := libpod.AttachStreams{
OutputStream: stdoutWriter, OutputStream: stdoutWriter,
InputStream: pr, InputStream: bufio.NewReader(pr),
// Runc eats the error stream // Runc eats the error stream
ErrorStream: stdoutWriter, ErrorStream: stdoutWriter,
AttachInput: true, AttachInput: true,