diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-02 15:30:57 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-02 15:30:57 +0200 |
commit | a70c44a9f6eb66ceedc38f3258d5a1b159b1db6c (patch) | |
tree | 7d577fb52c66a75f39c5733d897b40d9c105b5e2 /src | |
parent | 91c1822473923049755782fcb6d0e101556f4a16 (diff) |
Create /var/run/wireguard if non-existent
Diffstat (limited to 'src')
-rw-r--r-- | src/uapi_linux.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/uapi_linux.go b/src/uapi_linux.go index 17c5a9d..fd83918 100644 --- a/src/uapi_linux.go +++ b/src/uapi_linux.go @@ -6,6 +6,7 @@ import ( "golang.org/x/sys/unix" "net" "os" + "path" "time" ) @@ -15,6 +16,8 @@ const ( ipcErrorNoKeyValue = int64(unix.EPROTO) ipcErrorInvalidKey = int64(unix.EPROTO) ipcErrorInvalidValue = int64(unix.EPROTO) + socketDirectory = "/var/run/wireguard" + socketName = "%s.sock" ) /* TODO: @@ -77,9 +80,20 @@ func connectUnixSocket(path string) (net.Listener, error) { func NewUAPIListener(name string) (net.Listener, error) { + // check if path exist + + err := os.MkdirAll(socketDirectory, 077) + if err != nil && !os.IsExist(err) { + return nil, err + } + // open UNIX socket - socketPath := fmt.Sprintf("/var/run/wireguard/%s.sock", name) + socketPath := path.Join( + socketDirectory, + fmt.Sprintf(socketName, name), + ) + listener, err := connectUnixSocket(socketPath) if err != nil { return nil, err |