From 21d256d7da8e29baafc825dad4301cd7c043d5f2 Mon Sep 17 00:00:00 2001 From: Catalin Ancutei <37979489+Catalyn45@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:32:32 +0300 Subject: [PATCH] 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 --- os_windows.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/os_windows.go b/os_windows.go index 4eefe832..a07821fc 100644 --- a/os_windows.go +++ b/os_windows.go @@ -8,6 +8,7 @@ import ( "os/user" "path/filepath" "strings" + "syscall" "golang.org/x/sys/windows" ) @@ -24,8 +25,8 @@ var envPathExt = os.Getenv("PATHEXT") var ( gDefaultShell = "cmd" gDefaultShellFlag = "/c" - gDefaultSocketProt = "tcp" - gDefaultSocketPath = "127.0.0.1:12345" + gDefaultSocketProt = "unix" + gDefaultSocketPath string ) var ( @@ -98,6 +99,16 @@ func init() { gMarksPath = filepath.Join(data, "lf", "marks") gTagsPath = filepath.Join(data, "lf", "tags") 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 {