From b3d9eab1fedff8e98c77bc3373c2fcd0d65b5dce Mon Sep 17 00:00:00 2001
From: Brad Fitzpatrick <bradfitz@tailscale.com>
Date: Tue, 3 Mar 2020 11:47:21 -0800
Subject: [PATCH] safesocket: make some effort to create parent directory of
 sock

---
 safesocket/unixsocket.go | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/safesocket/unixsocket.go b/safesocket/unixsocket.go
index 8e5bd8b92..2722580be 100644
--- a/safesocket/unixsocket.go
+++ b/safesocket/unixsocket.go
@@ -10,6 +10,7 @@ import (
 	"fmt"
 	"net"
 	"os"
+	"path/filepath"
 )
 
 // TODO(apenwarr): handle magic cookie auth
@@ -39,6 +40,7 @@ func listen(path string, port uint16) (ln net.Listener, _ uint16, err error) {
 		return nil, 0, fmt.Errorf("%v: address already in use", path)
 	}
 	_ = os.Remove(path)
+	os.MkdirAll(filepath.Dir(path), 0755) // best effort
 	pipe, err := net.Listen("unix", path)
 	if err != nil {
 		return nil, 0, err