Skip to content

Commit

Permalink
Avoid wlhax socket collisions
Browse files Browse the repository at this point in the history
This allows running multiple wlhax instances, should one have a reason
to do so.
  • Loading branch information
kennylevinsen committed Mar 23, 2024
1 parent d85d853 commit 570cd1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 570cd1a

Please sign in to comment.