From 9fb24ac1e974c399979190b0d4c86643304dfc7e Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 5 Dec 2022 17:21:09 +0000 Subject: [PATCH] avoid using wayland-0 as a socket name --- src/Compositor.cpp | 12 +++++++++--- src/Compositor.hpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 5cf43334..9cf5e272 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -345,15 +345,21 @@ void CCompositor::startCompositor() { initAllSignals(); - m_szWLDisplaySocket = wl_display_add_socket_auto(m_sWLDisplay); + // get socket, avoid using 0 + for (int candidate = 1; candidate <= 32; candidate++) { + if (wl_display_add_socket(m_sWLDisplay, ("wayland-" + std::to_string(candidate)).c_str()) >= 0) { + m_szWLDisplaySocket = "wayland-" + std::to_string(candidate); + break; + } + } - if (!m_szWLDisplaySocket) { + if (m_szWLDisplaySocket.empty()) { Debug::log(CRIT, "m_szWLDisplaySocket NULL!"); wlr_backend_destroy(m_sWLRBackend); throw std::runtime_error("m_szWLDisplaySocket was null! (wl_display_add_socket_auto failed)"); } - setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket, 1); + setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket.c_str(), 1); signal(SIGPIPE, SIG_IGN); diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 9d32692f..125a61eb 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -76,7 +76,7 @@ public: // ------------------------------------------------- // - const char* m_szWLDisplaySocket; + std::string m_szWLDisplaySocket = ""; std::string m_szInstanceSignature = ""; std::string m_szCurrentSplash = "error";