wayfire icon indicating copy to clipboard operation
wayfire copied to clipboard

Make socket path unique

Open marcusbritanicus opened this issue 1 year ago • 4 comments

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

marcusbritanicus avatar Oct 07 '24 13:10 marcusbritanicus

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

ammen99 avatar Oct 07 '24 14:10 ammen99

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);
}

killown avatar Oct 07 '24 15:10 killown

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

marcusbritanicus avatar Oct 08 '24 19:10 marcusbritanicus

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 :)

ammen99 avatar Oct 09 '24 13:10 ammen99