Skip to content

Commit

Permalink
Do not allow to close /dev/stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
fr05t1k committed Oct 26, 2018
1 parent a26fc91 commit d59c91a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion connector/manager/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package manager
import (
"fmt"
api "github.com/fsouza/go-dockerclient"
"io"
"os"
)

Expand All @@ -18,6 +19,15 @@ func NewDocker(client *api.Client, id string) *Docker {
}
}

// Do not allow to close reader (i.e. /dev/stdin which docker client tries to close after command execution)
type noClosableReader struct {
wrappedReader io.Reader
}

func (w *noClosableReader) Read(p []byte) (n int, err error) {
return w.wrappedReader.Read(p)
}

func (dc *Docker) Exec(cmd []string) error {
execCmd, err := dc.client.CreateExec(api.CreateExecOptions{
AttachStdin: true,
Expand All @@ -33,7 +43,7 @@ func (dc *Docker) Exec(cmd []string) error {
}

return dc.client.StartExec(execCmd.ID, api.StartExecOptions{
InputStream: os.Stdin,
InputStream: &noClosableReader{os.Stdin},
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
RawTerminal: true,
Expand Down

0 comments on commit d59c91a

Please sign in to comment.