Skip to content

Commit cf9371f

Browse files
committed
UAPI for macOS
Signed-off-by: Jan Noha <nohajc@gmail.com>
1 parent 469159e commit cf9371f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

ipc/uapi_bsd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func UAPIListen(name string, file *os.File) (net.Listener, error) {
7979
if err != nil {
8080
return nil, err
8181
}
82-
uapi.keventFd, err = unix.Open(socketDirectory, unix.O_RDONLY, 0)
82+
uapi.keventFd, err = unix.Open(sockDir(), unix.O_RDONLY, 0)
8383
if err != nil {
8484
unix.Close(uapi.kqueueFd)
8585
return nil, err

ipc/uapi_unix.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"net"
1414
"os"
15+
"strings"
1516

1617
"golang.org/x/sys/unix"
1718
)
@@ -28,12 +29,24 @@ const (
2829
// flag in wireguard-android.
2930
var socketDirectory = "/var/run/wireguard"
3031

32+
const NET_EXT_APP_ID = "com.wireguard.macos.network-extension"
33+
34+
func sockDir() string {
35+
baseDir := socketDirectory
36+
homeDir, err := os.UserHomeDir()
37+
if err == nil && strings.Contains(homeDir, NET_EXT_APP_ID) {
38+
// this is a macOS sandboxed app, so we don't have access to /var/run
39+
baseDir = homeDir
40+
}
41+
return baseDir
42+
}
43+
3144
func sockPath(iface string) string {
32-
return fmt.Sprintf("%s/%s.sock", socketDirectory, iface)
45+
return fmt.Sprintf("%s/%s.sock", sockDir(), iface)
3346
}
3447

3548
func UAPIOpen(name string) (*os.File, error) {
36-
if err := os.MkdirAll(socketDirectory, 0o755); err != nil {
49+
if err := os.MkdirAll(sockDir(), 0o755); err != nil {
3750
return nil, err
3851
}
3952

0 commit comments

Comments
 (0)