aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Compositor.cpp
diff options
context:
space:
mode:
authordiniamo <[email protected]>2024-07-22 11:16:25 +0000
committerGitHub <[email protected]>2024-07-22 13:16:25 +0200
commitd03fa94c2ca1a642959e31adc4fcc2447a3cc623 (patch)
tree5ef6f076b04fb0f598cf56d3e9270cb91c7cc3c2 /src/Compositor.cpp
parent511e9ccdd199a90a7378fae1f950de6a315cc406 (diff)
downloadHyprland-d03fa94c2ca1a642959e31adc4fcc2447a3cc623.tar.gz
Hyprland-d03fa94c2ca1a642959e31adc4fcc2447a3cc623.zip
core: avoid locking 2 wayland sockets (#6971)
* fix: avoid locking 2 wayland sockets * format * fix formatting
Diffstat (limited to 'src/Compositor.cpp')
-rw-r--r--src/Compositor.cpp69
1 files changed, 20 insertions, 49 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 02ca5363..e3ef664d 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -207,7 +207,7 @@ void CCompositor::setRandomSplash() {
static std::vector<SP<Aquamarine::IOutput>> pendingOutputs;
//
-void CCompositor::initServer() {
+void CCompositor::initServer(std::string socketName, int socketFd) {
m_sWLDisplay = wl_display_create();
@@ -267,16 +267,25 @@ void CCompositor::initServer() {
m_iDRMFD = m_pAqBackend->drmFD();
Debug::log(LOG, "Running on DRMFD: {}", m_iDRMFD);
- // get socket, avoid using 0
- for (int candidate = 1; candidate <= 32; candidate++) {
- const auto CANDIDATESTR = ("wayland-" + std::to_string(candidate));
- const auto RETVAL = wl_display_add_socket(m_sWLDisplay, CANDIDATESTR.c_str());
+ if (!socketName.empty() && socketFd != -1) {
+ fcntl(socketFd, F_SETFD, FD_CLOEXEC);
+ const auto RETVAL = wl_display_add_socket_fd(m_sWLDisplay, socketFd);
if (RETVAL >= 0) {
- m_szWLDisplaySocket = CANDIDATESTR;
- Debug::log(LOG, "wl_display_add_socket for {} succeeded with {}", CANDIDATESTR, RETVAL);
- break;
- } else {
- Debug::log(WARN, "wl_display_add_socket for {} returned {}: skipping candidate {}", CANDIDATESTR, RETVAL, candidate);
+ m_szWLDisplaySocket = socketName;
+ Debug::log(LOG, "wl_display_add_socket_fd for {} succeeded with {}", socketName, RETVAL);
+ } else
+ Debug::log(WARN, "wl_display_add_socket_fd for {} returned {}: skipping", socketName, RETVAL);
+ } else {
+ // get socket, avoid using 0
+ for (int candidate = 1; candidate <= 32; candidate++) {
+ const auto CANDIDATESTR = ("wayland-" + std::to_string(candidate));
+ const auto RETVAL = wl_display_add_socket(m_sWLDisplay, CANDIDATESTR.c_str());
+ if (RETVAL >= 0) {
+ m_szWLDisplaySocket = CANDIDATESTR;
+ Debug::log(LOG, "wl_display_add_socket for {} succeeded with {}", CANDIDATESTR, RETVAL);
+ break;
+ } else
+ Debug::log(WARN, "wl_display_add_socket for {} returned {}: skipping candidate {}", CANDIDATESTR, RETVAL, candidate);
}
}
@@ -292,7 +301,6 @@ void CCompositor::initServer() {
throwError("m_szWLDisplaySocket was null! (wl_display_add_socket and wl_display_add_socket_auto failed)");
}
- Debug::log(LOG, "Setting WAYLAND_DISPLAY to {}", m_szWLDisplaySocket);
setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket.c_str(), 1);
setenv("XDG_SESSION_TYPE", "wayland", 1);
@@ -631,44 +639,7 @@ void CCompositor::prepareFallbackOutput() {
headless->createOutput();
}
-void CCompositor::startCompositor(std::string socketName, int socketFd) {
- if (!socketName.empty() && socketFd != -1) {
- fcntl(socketFd, F_SETFD, FD_CLOEXEC);
- const auto RETVAL = wl_display_add_socket_fd(m_sWLDisplay, socketFd);
- if (RETVAL >= 0) {
- m_szWLDisplaySocket = socketName;
- Debug::log(LOG, "wl_display_add_socket_fd for {} succeeded with {}", socketName, RETVAL);
- } else
- Debug::log(WARN, "wl_display_add_socket_fd for {} returned {}: skipping", socketName, RETVAL);
- } else {
- // get socket, avoid using 0
- for (int candidate = 1; candidate <= 32; candidate++) {
- const auto CANDIDATESTR = ("wayland-" + std::to_string(candidate));
- const auto RETVAL = wl_display_add_socket(m_sWLDisplay, CANDIDATESTR.c_str());
- if (RETVAL >= 0) {
- m_szWLDisplaySocket = CANDIDATESTR;
- Debug::log(LOG, "wl_display_add_socket for {} succeeded with {}", CANDIDATESTR, RETVAL);
- break;
- } else
- Debug::log(WARN, "wl_display_add_socket for {} returned {}: skipping candidate {}", CANDIDATESTR, RETVAL, candidate);
- }
- }
-
- if (m_szWLDisplaySocket.empty()) {
- Debug::log(WARN, "All candidates failed, trying wl_display_add_socket_auto");
- const auto SOCKETSTR = wl_display_add_socket_auto(m_sWLDisplay);
- if (SOCKETSTR)
- m_szWLDisplaySocket = SOCKETSTR;
- }
-
- if (m_szWLDisplaySocket.empty()) {
- Debug::log(CRIT, "m_szWLDisplaySocket NULL!");
- throwError("m_szWLDisplaySocket was null! (wl_display_add_socket and wl_display_add_socket_auto failed)");
- }
-
- setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket.c_str(), 1);
- setenv("XDG_SESSION_TYPE", "wayland", 1);
-
+void CCompositor::startCompositor() {
signal(SIGPIPE, SIG_IGN);
if (m_pAqBackend->hasSession() /* Session-less Hyprland usually means a nest, don't update the env in that case */) {