From 570cd1a3d33a3f6850301247ded3c2488f63c461 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 23 Mar 2024 18:03:44 +0100 Subject: [PATCH] Avoid wlhax socket collisions This allows running multiple wlhax instances, should one have a reason to do so. --- main.go | 16 +++++++++++++--- proxy.go | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index b58e581..e81e369 100644 --- a/main.go +++ b/main.go @@ -4,22 +4,32 @@ import ( "os" "time" "os/exec" + "fmt" libui "git.sr.ht/~sircmpwn/aerc/lib/ui" ) -const proxyDisplay = "wlhax-0" - func main() { remoteDisplay, ok := os.LookupEnv("WAYLAND_DISPLAY") if !ok { panic("No WAYLAND_DISPLAY set") } - proxy, err := NewProxy(proxyDisplay, remoteDisplay) + var ( + err error + path string + proxy *Proxy + ) + for idx := 0; idx < 10; idx++ { + path = fmt.Sprintf("wlhax-%d", idx) + if proxy, err = NewProxy(path, remoteDisplay); err == nil { + break + } + } if err != nil { panic(err) } + defer os.Remove(path) go proxy.Run() defer proxy.Close() diff --git a/proxy.go b/proxy.go index 5389aca..ee86f21 100644 --- a/proxy.go +++ b/proxy.go @@ -88,7 +88,6 @@ func NewProxy(proxyDisplay, remoteDisplay string) (*Proxy, error) { } else { proxyPath = proxyDisplay } - os.Remove(proxyPath) l, err := net.Listen("unix", proxyPath) if err != nil {