aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-12-15 20:52:53 +0100
committerSimon Ser <contact@emersion.fr>2020-12-15 20:52:53 +0100
commit87bd718de54ced41544e88200418bc091a1fce50 (patch)
tree4b2b1427f5e3050070e2b88a75f10868c9bf58f9 /backend
parent1ca4d6b0296ad23a59ad30fbc9063fa93b94b5fe (diff)
backend: use fcntl(F_DUPFD_CLOEXEC) instead of dup
This makes sure the CLOEXEC flag is set on the dup'ed FD.
Diffstat (limited to 'backend')
-rw-r--r--backend/headless/backend.c13
-rw-r--r--backend/wayland/backend.c6
-rw-r--r--backend/x11/backend.c10
3 files changed, 16 insertions, 13 deletions
diff --git a/backend/headless/backend.c b/backend/headless/backend.c
index 3995d1eb..c6c2d0f9 100644
--- a/backend/headless/backend.c
+++ b/backend/headless/backend.c
@@ -1,6 +1,7 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <drm_fourcc.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <wlr/interfaces/wlr_input_device.h>
@@ -113,19 +114,19 @@ static bool backend_init(struct wlr_headless_backend *backend,
backend->renderer = renderer;
backend->egl = wlr_gles2_renderer_get_egl(renderer);
- int fd = wlr_renderer_get_drm_fd(renderer);
- if (fd < 0) {
+ int drm_fd = wlr_renderer_get_drm_fd(renderer);
+ if (drm_fd < 0) {
wlr_log(WLR_ERROR, "Failed to get DRM device FD from renderer");
return false;
}
- fd = dup(fd);
- if (fd < 0) {
- wlr_log_errno(WLR_ERROR, "dup failed");
+ drm_fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 0);
+ if (drm_fd < 0) {
+ wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed");
return false;
}
- struct wlr_gbm_allocator *alloc = wlr_gbm_allocator_create(fd);
+ struct wlr_gbm_allocator *alloc = wlr_gbm_allocator_create(drm_fd);
if (alloc == NULL) {
wlr_log(WLR_ERROR, "Failed to create GBM allocator");
return false;
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c
index 14b6ca6c..5b8bce9b 100644
--- a/backend/wayland/backend.c
+++ b/backend/wayland/backend.c
@@ -1,4 +1,6 @@
+#define _POSIX_C_SOURCE 200809L
#include <assert.h>
+#include <fcntl.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
@@ -335,9 +337,9 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display,
goto error_event;
}
- drm_fd = dup(drm_fd);
+ drm_fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 0);
if (drm_fd < 0) {
- wlr_log_errno(WLR_ERROR, "dup failed");
+ wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed");
goto error_event;
}
diff --git a/backend/x11/backend.c b/backend/x11/backend.c
index 9482f86d..48f1aaee 100644
--- a/backend/x11/backend.c
+++ b/backend/x11/backend.c
@@ -1,6 +1,6 @@
-#define _POSIX_C_SOURCE 200112L
-
+#define _POSIX_C_SOURCE 200809L
#include <assert.h>
+#include <fcntl.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
@@ -490,9 +490,9 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
return false;
}
- drm_fd = dup(drm_fd);
- if (fd < 0) {
- wlr_log_errno(WLR_ERROR, "dup failed");
+ drm_fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 0);
+ if (drm_fd < 0) {
+ wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed");
return false;
}