mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-27 00:45:58 +01:00
parent
cb63398f07
commit
df0c014ba0
1 changed files with 13 additions and 5 deletions
|
@ -155,6 +155,14 @@ static int xwaylandReady(int fd, uint32_t mask, void* data) {
|
||||||
return g_pXWayland->pServer->ready(fd, mask);
|
return g_pXWayland->pServer->ready(fd, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool safeRemove(const std::string& path) {
|
||||||
|
try {
|
||||||
|
return std::filesystem::remove(path);
|
||||||
|
} catch (std::exception& e) { Debug::log(ERR, "[XWayland] failed to remove {}", path); }
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CXWaylandServer::tryOpenSockets() {
|
bool CXWaylandServer::tryOpenSockets() {
|
||||||
for (size_t i = 0; i <= 32; ++i) {
|
for (size_t i = 0; i <= 32; ++i) {
|
||||||
auto LOCK = std::format("/tmp/.X{}-lock", i);
|
auto LOCK = std::format("/tmp/.X{}-lock", i);
|
||||||
|
@ -162,7 +170,7 @@ bool CXWaylandServer::tryOpenSockets() {
|
||||||
if (int fd = open(LOCK.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0444); fd >= 0) {
|
if (int fd = open(LOCK.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0444); fd >= 0) {
|
||||||
// we managed to open the lock
|
// we managed to open the lock
|
||||||
if (!openSockets(xFDs, i)) {
|
if (!openSockets(xFDs, i)) {
|
||||||
std::filesystem::remove(LOCK);
|
safeRemove(LOCK);
|
||||||
close(fd);
|
close(fd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +178,7 @@ bool CXWaylandServer::tryOpenSockets() {
|
||||||
const auto PIDSTR = std::format("{}", getpid());
|
const auto PIDSTR = std::format("{}", getpid());
|
||||||
|
|
||||||
if (write(fd, PIDSTR.c_str(), PIDSTR.length()) != (long)PIDSTR.length()) {
|
if (write(fd, PIDSTR.c_str(), PIDSTR.length()) != (long)PIDSTR.length()) {
|
||||||
std::filesystem::remove(LOCK);
|
safeRemove(LOCK);
|
||||||
close(fd);
|
close(fd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -197,7 +205,7 @@ bool CXWaylandServer::tryOpenSockets() {
|
||||||
} catch (...) { continue; }
|
} catch (...) { continue; }
|
||||||
|
|
||||||
if (kill(pid, 0) != 0 && errno == ESRCH) {
|
if (kill(pid, 0) != 0 && errno == ESRCH) {
|
||||||
if (!std::filesystem::remove(LOCK))
|
if (!safeRemove(LOCK))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
i--;
|
i--;
|
||||||
|
@ -228,7 +236,7 @@ CXWaylandServer::~CXWaylandServer() {
|
||||||
close(xFDs[1]);
|
close(xFDs[1]);
|
||||||
|
|
||||||
auto LOCK = std::format("/tmp/.X{}-lock", display);
|
auto LOCK = std::format("/tmp/.X{}-lock", display);
|
||||||
std::filesystem::remove(LOCK);
|
safeRemove(LOCK);
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
@ -236,7 +244,7 @@ CXWaylandServer::~CXWaylandServer() {
|
||||||
#else
|
#else
|
||||||
path = std::format("/tmp/.X11-unix/X{}_", display);
|
path = std::format("/tmp/.X11-unix/X{}_", display);
|
||||||
#endif
|
#endif
|
||||||
std::filesystem::remove(path);
|
safeRemove(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWaylandServer::die() {
|
void CXWaylandServer::die() {
|
||||||
|
|
Loading…
Reference in a new issue