if (!dri2_dpy->device_name)
return;
- dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR);
+#ifdef O_CLOEXEC
+ dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR | O_CLOEXEC);
+ if (dri2_dpy->fd == -1 && errno == EINVAL)
+#endif
+ {
+ dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR);
+ if (dri2_dpy->fd != -1)
+ fcntl(dri2_dpy->fd, F_SETFD, fcntl(dri2_dpy->fd, F_GETFD) |
+ FD_CLOEXEC);
+ }
if (dri2_dpy->fd == -1) {
_eglLog(_EGL_WARNING, "wayland-egl: could not open %s (%s)",
dri2_dpy->device_name, strerror(errno));
if (!dri2_load_driver(disp))
goto cleanup_conn;
+#ifdef O_CLOEXEC
dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR | O_CLOEXEC);
+ if (dri2_dpy->fd == -1 && errno == EINVAL)
+#endif
+ {
+ dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR);
+ if (dri2_dpy->fd != -1)
+ fcntl(dri2_dpy->fd, F_SETFD, fcntl(dri2_dpy->fd, F_GETFD) |
+ FD_CLOEXEC);
+ }
if (dri2_dpy->fd == -1) {
_eglLog(_EGL_WARNING,
"DRI2: could not open %s (%s)", dri2_dpy->device_name,
gbm = dpy;
if (gbm == NULL) {
- fd = open("/dev/dri/card0", O_RDWR);
+ const char *device_name="/dev/dri/card0";
+#ifdef O_CLOEXEC
+ fd = open(device_name, O_RDWR | O_CLOEXEC);
+ if (fd == -1 && errno == EINVAL)
+#endif
+ {
+ fd = open(device_name, O_RDWR);
+ if (fd != -1)
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ }
/* FIXME: Use an internal constructor to create a gbm
* device with gallium backend directly, without setenv */
setenv("GBM_BACKEND", "gbm_gallium_drm.so", 1);
/* well, this makes fd 0 being ignored */
if (!dpy) {
- fd = open("/dev/fb0", O_RDWR);
+ const char *device_name="/dev/fb0";
+#ifdef O_CLOEXEC
+ fd = open(device_name, O_RDWR | O_CLOEXEC);
+ if (fd == -1 && errno == EINVAL)
+#endif
+ {
+ fd = open(device_name, O_RDWR);
+ if (fd != -1)
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ }
}
else {
fd = dup((int) pointer_to_intptr(dpy));
if (!drmdpy->device_name)
return;
- drmdpy->fd = open(drmdpy->device_name, O_RDWR);
+#ifdef O_CLOEXEC
+ drmdpy->fd = open(drmdpy->device_name, O_RDWR | O_CLOEXEC);
+ if (drmdpy->fd == -1 && errno == EINVAL)
+#endif
+ {
+ drmdpy->fd = open(drmdpy->device_name, O_RDWR);
+ if (drmdpy->fd != -1)
+ fcntl(drmdpy->fd, F_SETFD, fcntl(drmdpy->fd, F_GETFD) | FD_CLOEXEC);
+ }
if (drmdpy->fd == -1) {
_eglLog(_EGL_WARNING, "wayland-egl: could not open %s (%s)",
drmdpy->device_name, strerror(errno));
if (!x11_screen_probe_dri2(xscr, NULL, NULL))
return -1;
- fd = open(xscr->dri_device, O_RDWR);
+#ifdef O_CLOEXEC
+ fd = open(xscr->dri_device, O_RDWR | O_CLOEXEC);
+ if (fd == -1 && errno == EINVAL)
+#endif
+ {
+ fd = open(xscr->dri_device, O_RDWR);
+ if (fd != -1)
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ }
if (fd < 0) {
_eglLog(_EGL_WARNING, "failed to open %s", xscr->dri_device);
return -1;
goto handle_error;
}
- psc->fd = open(deviceName, O_RDWR);
+#ifdef O_CLOEXEC
+ psc->fd = open(deviceName, O_RDWR | O_CLOEXEC);
+ if (psc->fd == -1 && errno == EINVAL)
+#endif
+ {
+ psc->fd = open(deviceName, O_RDWR);
+ if (psc->fd != -1)
+ fcntl(psc->fd, F_SETFD, fcntl(psc->fd, F_GETFD) | FD_CLOEXEC);
+ }
if (psc->fd < 0) {
ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
goto handle_error;