diff options
author | gVisor bot <gvisor-bot@google.com> | 2019-09-25 16:44:22 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-09-25 16:44:22 -0700 |
commit | dd0e5eedaeb21582820856cbe68eb2a625f395aa (patch) | |
tree | 2c6e3e3ee7805040d09bddce488133ae09a4bb95 /pkg/fd | |
parent | 129c67d68ee2db4aa3a45ab6970e7d26348ce5ef (diff) | |
parent | 9ebd498a55fa87129cdc60cdc3bca66f26c49454 (diff) |
Merge pull request #765 from trailofbits:uds_support
PiperOrigin-RevId: 271235134
Diffstat (limited to 'pkg/fd')
-rw-r--r-- | pkg/fd/BUILD | 3 | ||||
-rw-r--r-- | pkg/fd/fd.go | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/pkg/fd/BUILD b/pkg/fd/BUILD index afa8f7659..c7f549428 100644 --- a/pkg/fd/BUILD +++ b/pkg/fd/BUILD @@ -8,6 +8,9 @@ go_library( srcs = ["fd.go"], importpath = "gvisor.dev/gvisor/pkg/fd", visibility = ["//visibility:public"], + deps = [ + "//pkg/unet", + ], ) go_test( diff --git a/pkg/fd/fd.go b/pkg/fd/fd.go index 83bcfe220..7691b477b 100644 --- a/pkg/fd/fd.go +++ b/pkg/fd/fd.go @@ -22,6 +22,8 @@ import ( "runtime" "sync/atomic" "syscall" + + "gvisor.dev/gvisor/pkg/unet" ) // ReadWriter implements io.ReadWriter, io.ReaderAt, and io.WriterAt for fd. It @@ -185,6 +187,12 @@ func OpenAt(dir *FD, path string, flags int, mode uint32) (*FD, error) { return New(f), nil } +// DialUnix connects to a Unix Domain Socket and return the file descriptor. +func DialUnix(path string) (*FD, error) { + socket, err := unet.Connect(path, false) + return New(socket.FD()), err +} + // Close closes the file descriptor contained in the FD. // // Close is safe to call multiple times, but will return an error after the |