unix sockets on windows (#1637)

* Added support for unix sockets on windows

* Keep the fallback port consistent with the one before

* Moved socket check at the bottom of the init function

* Creating the unix socket in temp dir
This commit is contained in:
Catalin Ancutei authored and GitHub committed 2024-04-07 15:32:32 +02:00
1 parent 47634f22bd
commit 21d256d7da
1 file changed
+13 -2
+13 -2
View File
@@ -8,6 +8,7 @@ import (
"os/user" "os/user"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
@@ -24,8 +25,8 @@ var envPathExt = os.Getenv("PATHEXT")
var ( var (
gDefaultShell = "cmd" gDefaultShell = "cmd"
gDefaultShellFlag = "/c" gDefaultShellFlag = "/c"
gDefaultSocketProt = "tcp" gDefaultSocketProt = "unix"
gDefaultSocketPath = "127.0.0.1:12345" gDefaultSocketPath string
) )
var ( var (
@@ -98,6 +99,16 @@ func init() {
gMarksPath = filepath.Join(data, "lf", "marks") gMarksPath = filepath.Join(data, "lf", "marks")
gTagsPath = filepath.Join(data, "lf", "tags") gTagsPath = filepath.Join(data, "lf", "tags")
gHistoryPath = filepath.Join(data, "lf", "history") gHistoryPath = filepath.Join(data, "lf", "history")
socket, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
if err != nil {
gDefaultSocketProt = "tcp"
gDefaultSocketPath = "127.0.0.1:12345"
} else {
runtime := os.TempDir()
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
syscall.Close(socket)
}
} }
func detachedCommand(name string, arg ...string) *exec.Cmd { func detachedCommand(name string, arg ...string) *exec.Cmd {