mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
Do not allow to close /dev/stdin
This commit is contained in:
@@ -3,6 +3,7 @@ package manager
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
api "github.com/fsouza/go-dockerclient"
|
api "github.com/fsouza/go-dockerclient"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -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 {
|
func (dc *Docker) Exec(cmd []string) error {
|
||||||
execCmd, err := dc.client.CreateExec(api.CreateExecOptions{
|
execCmd, err := dc.client.CreateExec(api.CreateExecOptions{
|
||||||
AttachStdin: true,
|
AttachStdin: true,
|
||||||
@@ -33,7 +43,7 @@ func (dc *Docker) Exec(cmd []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return dc.client.StartExec(execCmd.ID, api.StartExecOptions{
|
return dc.client.StartExec(execCmd.ID, api.StartExecOptions{
|
||||||
InputStream: os.Stdin,
|
InputStream: &noClosableReader{os.Stdin},
|
||||||
OutputStream: os.Stdout,
|
OutputStream: os.Stdout,
|
||||||
ErrorStream: os.Stderr,
|
ErrorStream: os.Stderr,
|
||||||
RawTerminal: true,
|
RawTerminal: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user