Beam: fix bug in beamsh which 'swapped' FDs because of underlying implementation of net.FileConn
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
b56b399238
commit
b1090576ae
2 changed files with 4 additions and 1 deletions
|
@ -67,8 +67,10 @@ func CmdCat(args []string, f *os.File) {
|
|||
func CmdEcho(args []string, f *os.File) {
|
||||
resp, err := beam.FdConn(int(f.Fd()))
|
||||
if err != nil {
|
||||
Fatal(err)
|
||||
return
|
||||
}
|
||||
defer resp.Close()
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -199,13 +199,14 @@ func USocketPair() (*net.UnixConn, *net.UnixConn, error) {
|
|||
|
||||
// FdConn wraps a file descriptor in a standard *net.UnixConn object, or
|
||||
// returns an error if the file descriptor does not point to a unix socket.
|
||||
// This creates a duplicate file descriptor. It's the caller's responsibility
|
||||
// to close both.
|
||||
func FdConn(fd int) (*net.UnixConn, error) {
|
||||
f := os.NewFile(uintptr(fd), fmt.Sprintf("%d", fd))
|
||||
conn, err := net.FileConn(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f.Close()
|
||||
uconn, ok := conn.(*net.UnixConn)
|
||||
if !ok {
|
||||
conn.Close()
|
||||
|
|
Loading…
Reference in a new issue