summaryrefslogtreecommitdiffhomepage
path: root/pkg/fd/fd.go
diff options
context:
space:
mode:
authorRobert Tonic <btonic@users.noreply.github.com>2019-09-05 07:16:36 -0400
committerRobert Tonic <btonic@users.noreply.github.com>2019-09-05 07:16:36 -0400
commit4573efe84b2d52112a9370dd5a469e9d11959ab4 (patch)
tree019a961a2e0faf8495d02d202b7fdba6971f6e07 /pkg/fd/fd.go
parent07d329d89f25e4649731199c3025f4fa0ed52bdb (diff)
Switch from net to unet to open Unix Domain Sockets.
Diffstat (limited to 'pkg/fd/fd.go')
-rw-r--r--pkg/fd/fd.go17
1 files changed, 4 insertions, 13 deletions
diff --git a/pkg/fd/fd.go b/pkg/fd/fd.go
index c3acd0fe2..7f1f9d984 100644
--- a/pkg/fd/fd.go
+++ b/pkg/fd/fd.go
@@ -22,7 +22,7 @@ import (
"runtime"
"sync/atomic"
"syscall"
- "net"
+ "gvisor.dev/gvisor/pkg/unet"
)
// ReadWriter implements io.ReadWriter, io.ReaderAt, and io.WriterAt for fd. It
@@ -186,19 +186,10 @@ func OpenAt(dir *FD, path string, flags int, mode uint32) (*FD, error) {
return New(f), nil
}
-// OpenUnix TODO: DOC
+// OpenUnix Open a Unix Domain Socket and return the file descriptor for it.
func OpenUnix(path string) (*FD, error) {
- addr, _ := net.ResolveUnixAddr("unix", path)
- f, err := net.DialUnix("unix", nil, addr); if err != nil {
- return nil, fmt.Errorf("unable to open socket: %q, err: %v", path, err)
- }
- fConnd, err := f.File(); if err != nil {
- return nil, fmt.Errorf("unable to convert to os.File: %q, err: %v", path, err)
- }
- fdConnd, err := NewFromFile(fConnd); if err != nil {
- return nil, fmt.Errorf("unable to convert os.File to fd.FD: %q, err: %v", path, err)
- }
- return fdConnd, nil
+ socket, err := unet.Connect(path, false)
+ return New(socket.FD()), err
}
// Close closes the file descriptor contained in the FD.