]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Create /var/run/wireguard if non-existent
authorMathias Hall-Andersen <mathias@hall-andersen.dk>
Wed, 2 Aug 2017 13:30:57 +0000 (15:30 +0200)
committerMathias Hall-Andersen <mathias@hall-andersen.dk>
Wed, 2 Aug 2017 13:30:57 +0000 (15:30 +0200)
src/uapi_linux.go

index 17c5a9d7b46c44487655ef999a0ca5c62fc47c9e..fd83918b9b4e98283aeea59bbe98cebe5093fc66 100644 (file)
@@ -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