From 9c4f3d447faf2686ebffe697371e15075b2e6480 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 27 Jul 2022 13:22:06 +0200 Subject: [PATCH] debug console: use FileDescriptor class --- src/backends/wayland/wayland_backend.cpp | 7 +++---- src/backends/wayland/wayland_backend.h | 3 ++- src/debug_console.cpp | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/backends/wayland/wayland_backend.cpp b/src/backends/wayland/wayland_backend.cpp index 7e47c24bd2..304d9c316b 100644 --- a/src/backends/wayland/wayland_backend.cpp +++ b/src/backends/wayland/wayland_backend.cpp @@ -581,13 +581,13 @@ WaylandBackend::WaylandBackend(QObject *parent) #if HAVE_WAYLAND_EGL char const *drm_render_node = "/dev/dri/renderD128"; - m_drmFileDescriptor = open(drm_render_node, O_RDWR); - if (m_drmFileDescriptor < 0) { + m_drmFileDescriptor = FileDescriptor(open(drm_render_node, O_RDWR)); + if (!m_drmFileDescriptor.isValid()) { qCWarning(KWIN_WAYLAND_BACKEND) << "Failed to open drm render node" << drm_render_node; m_gbmDevice = nullptr; return; } - m_gbmDevice = gbm_create_device(m_drmFileDescriptor); + m_gbmDevice = gbm_create_device(m_drmFileDescriptor.get()); #endif } @@ -622,7 +622,6 @@ WaylandBackend::~WaylandBackend() m_connectionThreadObject->deleteLater(); #if HAVE_WAYLAND_EGL gbm_device_destroy(m_gbmDevice); - close(m_drmFileDescriptor); #endif qCDebug(KWIN_WAYLAND_BACKEND) << "Destroyed Wayland display"; } diff --git a/src/backends/wayland/wayland_backend.h b/src/backends/wayland/wayland_backend.h index 5409ace66b..c3b6ad1e22 100644 --- a/src/backends/wayland/wayland_backend.h +++ b/src/backends/wayland/wayland_backend.h @@ -14,6 +14,7 @@ #include "inputbackend.h" #include "inputdevice.h" #include "platform.h" +#include "utils/filedescriptor.h" #include // Qt #include @@ -356,7 +357,7 @@ private: KWayland::Client::ServerSideDecorationManager *ssdManager(); int m_nextId = 0; #if HAVE_WAYLAND_EGL - int m_drmFileDescriptor = 0; + FileDescriptor m_drmFileDescriptor; gbm_device *m_gbmDevice; #endif }; diff --git a/src/debug_console.cpp b/src/debug_console.cpp index 2dceb19d00..e03ebd9225 100644 --- a/src/debug_console.cpp +++ b/src/debug_console.cpp @@ -15,6 +15,7 @@ #include "main.h" #include "scene.h" #include "unmanaged.h" +#include "utils/filedescriptor.h" #include "utils/subsurfacemonitor.h" #include "wayland/abstract_data_source.h" #include "wayland/clientconnection.h" @@ -1642,9 +1643,7 @@ static QByteArray readData(int fd) pollfd pfd; pfd.fd = fd; pfd.events = POLLIN; - auto closeFd = qScopeGuard([fd] { - close(fd); - }); + FileDescriptor closeFd{fd}; QByteArray data; while (true) { const int ready = poll(&pfd, 1, 1000);