aboutsummaryrefslogtreecommitdiff
path: root/backend/drm/renderer.c
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-12-15 20:49:28 +0100
committerSimon Ser <contact@emersion.fr>2020-12-15 20:50:04 +0100
commit1ca4d6b0296ad23a59ad30fbc9063fa93b94b5fe (patch)
tree55a404087d30193efa3fc3cfb297e93e04f513bc /backend/drm/renderer.c
parent3fd809888184c0e629bea2b628e2caca622bab88 (diff)
backend/drm: dup FD before wlr_gbm_allocator_create
The GBM allocator takes ownership of the DRM FD.
Diffstat (limited to 'backend/drm/renderer.c')
-rw-r--r--backend/drm/renderer.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c
index 79add1ba..7599623a 100644
--- a/backend/drm/renderer.c
+++ b/backend/drm/renderer.c
@@ -1,5 +1,7 @@
+#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <drm_fourcc.h>
+#include <fcntl.h>
#include <gbm.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -37,9 +39,16 @@ bool init_drm_renderer(struct wlr_drm_backend *drm,
goto error_gbm;
}
- renderer->allocator = wlr_gbm_allocator_create(drm->fd);
+ int alloc_fd = fcntl(drm->fd, F_DUPFD_CLOEXEC, 0);
+ if (alloc_fd < 0) {
+ wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed");
+ goto error_wlr_rend;
+ }
+
+ renderer->allocator = wlr_gbm_allocator_create(alloc_fd);
if (renderer->allocator == NULL) {
wlr_log(WLR_ERROR, "Failed to create allocator");
+ close(alloc_fd);
goto error_wlr_rend;
}