diff options
author | trianta <[email protected]> | 2024-11-03 08:59:46 -0600 |
---|---|---|
committer | GitHub <[email protected]> | 2024-11-03 14:59:46 +0000 |
commit | 5833abbbd11dca718379863cb2fb5c2423f5d7e7 (patch) | |
tree | 4b337ba08e57fdf78113559115382fe276a88d16 | |
parent | 514e0ff509f3bf4c98515f08216ac2eeb8797517 (diff) | |
download | Hyprland-5833abbbd11dca718379863cb2fb5c2423f5d7e7.tar.gz Hyprland-5833abbbd11dca718379863cb2fb5c2423f5d7e7.zip |
xwayland: minor fixups for stability (#8323)
* xwayland: add inline safe closing of fds and fix LOCK_FILE_MODE permissions
* xwayland: auto recreate xwayland instance if it crashes
* xwayland: delay auto-restart until later
-rw-r--r-- | src/xwayland/Server.cpp | 25 | ||||
-rw-r--r-- | src/xwayland/XWM.cpp | 3 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/xwayland/Server.cpp b/src/xwayland/Server.cpp index 5ad9ff23..f356af18 100644 --- a/src/xwayland/Server.cpp +++ b/src/xwayland/Server.cpp @@ -30,7 +30,7 @@ constexpr int SOCKET_DIR_PERMISSIONS = 0755; constexpr int SOCKET_BACKLOG = 1; constexpr int MAX_SOCKET_RETRIES = 32; -constexpr int LOCK_FILE_MODE = 044; +constexpr int LOCK_FILE_MODE = 0444; static bool setCloseOnExec(int fd, bool cloexec) { int flags = fcntl(fd, F_GETFD); @@ -58,6 +58,11 @@ void cleanUpSocket(int fd, const char* path) { unlink(path); } +inline void closeSocketSafely(int& fd) { + if (fd >= 0) + close(fd); +} + static int createSocket(struct sockaddr_un* addr, size_t path_size) { socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1; int fd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -252,8 +257,8 @@ CXWaylandServer::~CXWaylandServer() { if (display < 0) return; - close(xFDs[0]); - close(xFDs[1]); + closeSocketSafely(xFDs[0]); + closeSocketSafely(xFDs[1]); std::string lockPath = std::format("/tmp/.X{}-lock", display); safeRemove(lockPath); @@ -283,14 +288,10 @@ void CXWaylandServer::die() { if (pipeFd >= 0) close(pipeFd); - if (waylandFDs[0] >= 0) - close(waylandFDs[0]); - if (waylandFDs[1] >= 0) - close(waylandFDs[1]); - if (xwmFDs[0] >= 0) - close(xwmFDs[0]); - if (xwmFDs[1] >= 0) - close(xwmFDs[1]); + closeSocketSafely(waylandFDs[0]); + closeSocketSafely(waylandFDs[1]); + closeSocketSafely(xwmFDs[0]); + closeSocketSafely(xwmFDs[1]); // possible crash. Better to leak a bit. //if (xwaylandClient) @@ -407,7 +408,7 @@ bool CXWaylandServer::start() { close(notify[1]); close(waylandFDs[1]); - close(xwmFDs[1]); + closeSocketSafely(xwmFDs[1]); waylandFDs[1] = -1; xwmFDs[1] = -1; diff --git a/src/xwayland/XWM.cpp b/src/xwayland/XWM.cpp index 248813bf..87fc34e4 100644 --- a/src/xwayland/XWM.cpp +++ b/src/xwayland/XWM.cpp @@ -13,6 +13,7 @@ #include "../defines.hpp" #include "../Compositor.hpp" #include "../protocols/core/Seat.hpp" +#include "../managers/eventLoop/EventLoopManager.hpp" #include "../managers/SeatManager.hpp" #include "../protocols/XWaylandShell.hpp" #include "../protocols/core/Compositor.hpp" @@ -691,6 +692,8 @@ int CXWM::onEvent(int fd, uint32_t mask) { Debug::log(CRIT, "XWayland has yeeten the xwm off?!"); g_pXWayland->pWM.reset(); g_pXWayland->pServer.reset(); + // Attempt to create fresh instance + g_pEventLoopManager->doLater([]() { g_pXWayland = std::make_unique<CXWayland>(true); }); return 0; } |