fix: SSH control socket path in WSL2 when runtime dir doesn't exist (fixes #319)

This commit is contained in:
Pasha Sviderski
2026-04-20 14:36:26 +10:00
parent 84990ad692
commit 3a79aeffcc
2 changed files with 17 additions and 4 deletions
+6 -2
View File
@@ -45,9 +45,13 @@ func controlSocketPath() string {
// of the ProxyJump option. This ensures that shared connections are uniquely identified.
sockName := fmt.Sprintf("uc_control_%%C.sock")
// Prefer XDG_RUNTIME_DIR if set, fall back to ~/.ssh if it exists.
// Prefer XDG_RUNTIME_DIR if set and the directory exists, fall back to ~/.ssh if it exists.
if dir := os.Getenv("XDG_RUNTIME_DIR"); dir != "" {
return filepath.Join(dir, sockName)
// On WSL2 without systemd, XDG_RUNTIME_DIR may be set to /run/user/$UID that doesn't actually exist,
// so existence must be verified before use: https://github.com/psviderski/uncloud/issues/319.
if fi, err := os.Stat(dir); err == nil && fi.IsDir() {
return filepath.Join(dir, sockName)
}
}
if home, err := os.UserHomeDir(); err == nil {
sshDir := filepath.Join(home, ".ssh")