Skip to content

Commit 0395014

Browse files
committed
FIX: Darwin not based on /dev/vsock file
1 parent a2d6b16 commit 0395014

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

fd_darwin.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@ package vsock
22

33
import (
44
"fmt"
5-
"os"
65

76
"golang.org/x/sys/unix"
87
)
98

109
// contextID retrieves the local context ID for this system.
1110
func contextID() (uint32, error) {
12-
f, err := os.Open(devVsock)
13-
if err != nil {
14-
return 0, err
15-
}
16-
defer f.Close()
11+
if fd, err := unix.Socket(unix.AF_VSOCK, unix.SOCK_STREAM, 0); err != nil {
12+
return 2, nil
13+
} else {
14+
defer unix.Close(fd)
1715

18-
cid, err := unix.IoctlGetInt(int(f.Fd()), unix.IOCTL_VM_SOCKETS_GET_LOCAL_CID)
16+
cid, err := unix.IoctlGetInt(fd, unix.IOCTL_VM_SOCKETS_GET_LOCAL_CID)
1917

20-
return uint32(cid), err
18+
return uint32(cid), err
19+
}
2120
}
2221

2322
// isErrno determines if an error a matches UNIX error number.

vsock_darwin_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,6 @@ func Test_opError(t *testing.T) {
8686
Err: errClosed,
8787
},
8888
},
89-
{
90-
name: "special PathError /dev/vsock",
91-
err: &os.PathError{
92-
Op: "open",
93-
Path: devVsock,
94-
Err: unix.ENOENT,
95-
},
96-
want: &net.OpError{
97-
Err: &os.PathError{
98-
Op: "open",
99-
Path: devVsock,
100-
Err: unix.ENOENT,
101-
},
102-
},
103-
},
10489
{
10590
name: "op close",
10691
op: opClose,

0 commit comments

Comments
 (0)