WayfireWM / wayfire

A modular and extensible wayland compositor
https://wayfire.org/
MIT License
2.42k stars 179 forks source link

Make socket path unique #2490

Closed marcusbritanicus closed 1 month ago

marcusbritanicus commented 1 month ago

The solution proposed by @killown to make the socket path unique. I have tested this and confirm that it works.

ammen99 commented 1 month ago

If we're going to do this, move the socket to XDG_RUNTIME_DIR :)

killown commented 1 month ago

If we're going to do this, move the socket to XDG_RUNTIME_DIR :)


void init() override
{
    char *pre_socket = getenv("_WAYFIRE_SOCKET");
    const char *runtime_dir = getenv("XDG_RUNTIME_DIR");
    const auto& dname = wf::get_core().wayland_display;
    pid_t pid = getpid();

    std::string socket;
    if (pre_socket)
    {
        socket = pre_socket;
    }
    else if (runtime_dir)
    {
        socket = std::string(runtime_dir) + "/wayfire-" + dname + "-" + std::to_string(pid) + ".socket";
    }
    else
    {
        socket = "/tmp/wayfire-" + dname + "-" + std::to_string(pid) + ".socket";
    }

    setenv("WAYFIRE_SOCKET", socket.c_str(), 1);
    server->init(socket);
}
marcusbritanicus commented 1 month ago

@killown I think you should open a PR. You're clearly doing a much better job than I can.

ammen99 commented 1 month ago

I don't think we need the pid when the socket is in $XDG_RUNTIME_DIR, without the pid I also think it is just a little bit simpler to find the socket when running from somewhere where $WAYFIRE_SOCKET is not set. Otherwise @killown's patch lgtm, I don't know why you won't send a pr :)