summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Ancutei <37979489+Catalyn45@users.noreply.github.com>2024-04-07 16:32:32 +0300
committerGitHub <noreply@github.com>2024-04-07 15:32:32 +0200
commit21d256d7da8e29baafc825dad4301cd7c043d5f2 (patch)
treedbb216207450f871c6f4892b660b5906242d2f70
parent47634f22bd6eee1fd8d6a9c5bd588d3d41ded0fa (diff)
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
-rw-r--r--os_windows.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/os_windows.go b/os_windows.go
index 4eefe83..a07821f 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 {