mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-15 07:25:59 +01:00
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
This commit is contained in:
parent
514e0ff509
commit
5833abbbd1
2 changed files with 16 additions and 12 deletions
|
@ -30,7 +30,7 @@
|
||||||
constexpr int SOCKET_DIR_PERMISSIONS = 0755;
|
constexpr int SOCKET_DIR_PERMISSIONS = 0755;
|
||||||
constexpr int SOCKET_BACKLOG = 1;
|
constexpr int SOCKET_BACKLOG = 1;
|
||||||
constexpr int MAX_SOCKET_RETRIES = 32;
|
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) {
|
static bool setCloseOnExec(int fd, bool cloexec) {
|
||||||
int flags = fcntl(fd, F_GETFD);
|
int flags = fcntl(fd, F_GETFD);
|
||||||
|
@ -58,6 +58,11 @@ void cleanUpSocket(int fd, const char* path) {
|
||||||
unlink(path);
|
unlink(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void closeSocketSafely(int& fd) {
|
||||||
|
if (fd >= 0)
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
static int createSocket(struct sockaddr_un* addr, size_t path_size) {
|
static int createSocket(struct sockaddr_un* addr, size_t path_size) {
|
||||||
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
|
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
|
||||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
@ -252,8 +257,8 @@ CXWaylandServer::~CXWaylandServer() {
|
||||||
if (display < 0)
|
if (display < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
close(xFDs[0]);
|
closeSocketSafely(xFDs[0]);
|
||||||
close(xFDs[1]);
|
closeSocketSafely(xFDs[1]);
|
||||||
|
|
||||||
std::string lockPath = std::format("/tmp/.X{}-lock", display);
|
std::string lockPath = std::format("/tmp/.X{}-lock", display);
|
||||||
safeRemove(lockPath);
|
safeRemove(lockPath);
|
||||||
|
@ -283,14 +288,10 @@ void CXWaylandServer::die() {
|
||||||
if (pipeFd >= 0)
|
if (pipeFd >= 0)
|
||||||
close(pipeFd);
|
close(pipeFd);
|
||||||
|
|
||||||
if (waylandFDs[0] >= 0)
|
closeSocketSafely(waylandFDs[0]);
|
||||||
close(waylandFDs[0]);
|
closeSocketSafely(waylandFDs[1]);
|
||||||
if (waylandFDs[1] >= 0)
|
closeSocketSafely(xwmFDs[0]);
|
||||||
close(waylandFDs[1]);
|
closeSocketSafely(xwmFDs[1]);
|
||||||
if (xwmFDs[0] >= 0)
|
|
||||||
close(xwmFDs[0]);
|
|
||||||
if (xwmFDs[1] >= 0)
|
|
||||||
close(xwmFDs[1]);
|
|
||||||
|
|
||||||
// possible crash. Better to leak a bit.
|
// possible crash. Better to leak a bit.
|
||||||
//if (xwaylandClient)
|
//if (xwaylandClient)
|
||||||
|
@ -407,7 +408,7 @@ bool CXWaylandServer::start() {
|
||||||
|
|
||||||
close(notify[1]);
|
close(notify[1]);
|
||||||
close(waylandFDs[1]);
|
close(waylandFDs[1]);
|
||||||
close(xwmFDs[1]);
|
closeSocketSafely(xwmFDs[1]);
|
||||||
waylandFDs[1] = -1;
|
waylandFDs[1] = -1;
|
||||||
xwmFDs[1] = -1;
|
xwmFDs[1] = -1;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "../defines.hpp"
|
#include "../defines.hpp"
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../protocols/core/Seat.hpp"
|
#include "../protocols/core/Seat.hpp"
|
||||||
|
#include "../managers/eventLoop/EventLoopManager.hpp"
|
||||||
#include "../managers/SeatManager.hpp"
|
#include "../managers/SeatManager.hpp"
|
||||||
#include "../protocols/XWaylandShell.hpp"
|
#include "../protocols/XWaylandShell.hpp"
|
||||||
#include "../protocols/core/Compositor.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?!");
|
Debug::log(CRIT, "XWayland has yeeten the xwm off?!");
|
||||||
g_pXWayland->pWM.reset();
|
g_pXWayland->pWM.reset();
|
||||||
g_pXWayland->pServer.reset();
|
g_pXWayland->pServer.reset();
|
||||||
|
// Attempt to create fresh instance
|
||||||
|
g_pEventLoopManager->doLater([]() { g_pXWayland = std::make_unique<CXWayland>(true); });
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue