From 410c08cdc676de1f24d71d8817587e1f7e6b4093 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 29 Mar 2022 16:14:38 +0200 Subject: [PATCH] drm-lease-v1: skip device on wlr_drm_backend_get_non_master_fd failure On some setups, wlr_drm_backend_get_non_master_fd may fail because of permission issues. Instead of exposing a bogus global, bail out. Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3391 --- types/wlr_drm_lease_v1.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/types/wlr_drm_lease_v1.c b/types/wlr_drm_lease_v1.c index 7cb9974d..0ef9e036 100644 --- a/types/wlr_drm_lease_v1.c +++ b/types/wlr_drm_lease_v1.c @@ -621,10 +621,18 @@ static void handle_backend_destroy(struct wl_listener *listener, void *data) { static void drm_lease_device_v1_create(struct wlr_drm_lease_v1_manager *manager, struct wlr_backend *backend) { - assert(backend); + struct wlr_drm_backend *drm_backend = get_drm_backend_from_backend(backend); + + // Make sure we can get a non-master FD for the DRM backend. On some setups + // we don't have the permission for this. + int fd = wlr_drm_backend_get_non_master_fd(backend); + if (fd < 0) { + wlr_log(WLR_INFO, "Skipping %s: failed to get read-only DRM FD", + drm_backend->name); + return; + } + close(fd); - struct wlr_drm_backend *drm_backend = - get_drm_backend_from_backend(backend); wlr_log(WLR_DEBUG, "Creating wlr_drm_lease_device_v1 for %s", drm_backend->name);