Create /var/run/wireguard if non-existent

This commit is contained in:
Mathias Hall-Andersen 2017-08-02 15:30:57 +02:00
parent 91c1822473
commit a70c44a9f6

View file

@ -6,6 +6,7 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"net" "net"
"os" "os"
"path"
"time" "time"
) )
@ -15,6 +16,8 @@ const (
ipcErrorNoKeyValue = int64(unix.EPROTO) ipcErrorNoKeyValue = int64(unix.EPROTO)
ipcErrorInvalidKey = int64(unix.EPROTO) ipcErrorInvalidKey = int64(unix.EPROTO)
ipcErrorInvalidValue = int64(unix.EPROTO) ipcErrorInvalidValue = int64(unix.EPROTO)
socketDirectory = "/var/run/wireguard"
socketName = "%s.sock"
) )
/* TODO: /* TODO:
@ -77,9 +80,20 @@ func connectUnixSocket(path string) (net.Listener, error) {
func NewUAPIListener(name 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 // open UNIX socket
socketPath := fmt.Sprintf("/var/run/wireguard/%s.sock", name) socketPath := path.Join(
socketDirectory,
fmt.Sprintf(socketName, name),
)
listener, err := connectUnixSocket(socketPath) listener, err := connectUnixSocket(socketPath)
if err != nil { if err != nil {
return nil, err return nil, err