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) {
|
func CmdEcho(args []string, f *os.File) {
|
||||||
resp, err := beam.FdConn(int(f.Fd()))
|
resp, err := beam.FdConn(int(f.Fd()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Fatal(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer resp.Close()
|
||||||
r, w, err := os.Pipe()
|
r, w, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -199,13 +199,14 @@ func USocketPair() (*net.UnixConn, *net.UnixConn, error) {
|
||||||
|
|
||||||
// FdConn wraps a file descriptor in a standard *net.UnixConn object, or
|
// 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.
|
// 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) {
|
func FdConn(fd int) (*net.UnixConn, error) {
|
||||||
f := os.NewFile(uintptr(fd), fmt.Sprintf("%d", fd))
|
f := os.NewFile(uintptr(fd), fmt.Sprintf("%d", fd))
|
||||||
conn, err := net.FileConn(f)
|
conn, err := net.FileConn(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f.Close()
|
|
||||||
uconn, ok := conn.(*net.UnixConn)
|
uconn, ok := conn.(*net.UnixConn)
|
||||||
if !ok {
|
if !ok {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
Loading…
Reference in a new issue