summaryrefslogtreecommitdiff
path: root/src/xwayland/Server.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-06-15 16:06:02 +0200
committerVaxry <vaxry@vaxry.net>2024-06-15 16:06:07 +0200
commitdf0c014ba0c9c665df51fe7750ab9d7288b57478 (patch)
treed4ea7f977daa569233bbf0e88be863fde77eeb48 /src/xwayland/Server.cpp
parentcb63398f079b4b4324c04e2e41ba17983d66487c (diff)
xwayland: use safeRemove for removing files
fixes #6514
Diffstat (limited to 'src/xwayland/Server.cpp')
-rw-r--r--src/xwayland/Server.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/xwayland/Server.cpp b/src/xwayland/Server.cpp
index 26010cfb..e2dab412 100644
--- a/src/xwayland/Server.cpp
+++ b/src/xwayland/Server.cpp
@@ -155,6 +155,14 @@ static int xwaylandReady(int fd, uint32_t mask, void* data) {
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() {
for (size_t i = 0; i <= 32; ++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) {
// we managed to open the lock
if (!openSockets(xFDs, i)) {
- std::filesystem::remove(LOCK);
+ safeRemove(LOCK);
close(fd);
continue;
}
@@ -170,7 +178,7 @@ bool CXWaylandServer::tryOpenSockets() {
const auto PIDSTR = std::format("{}", getpid());
if (write(fd, PIDSTR.c_str(), PIDSTR.length()) != (long)PIDSTR.length()) {
- std::filesystem::remove(LOCK);
+ safeRemove(LOCK);
close(fd);
continue;
}
@@ -197,7 +205,7 @@ bool CXWaylandServer::tryOpenSockets() {
} catch (...) { continue; }
if (kill(pid, 0) != 0 && errno == ESRCH) {
- if (!std::filesystem::remove(LOCK))
+ if (!safeRemove(LOCK))
continue;
i--;
@@ -228,7 +236,7 @@ CXWaylandServer::~CXWaylandServer() {
close(xFDs[1]);
auto LOCK = std::format("/tmp/.X{}-lock", display);
- std::filesystem::remove(LOCK);
+ safeRemove(LOCK);
std::string path;
#ifdef __linux__
@@ -236,7 +244,7 @@ CXWaylandServer::~CXWaylandServer() {
#else
path = std::format("/tmp/.X11-unix/X{}_", display);
#endif
- std::filesystem::remove(path);
+ safeRemove(path);
}
void CXWaylandServer::die() {