Bug#651370: libgl1-mesa-glx: need close on exec for dri device
On Wed, Dec 7, 2011 at 23:43:13 -0600, David Fries wrote:
> diff -upr /tmp/mesa-7.11/src/egl/drivers/dri2/platform_wayland.c mesa-7.11/src/egl/drivers/dri2/platform_wayland.c
> --- /tmp/mesa-7.11/src/egl/drivers/dri2/platform_wayland.c 2011-07-08 20:37:09.000000000 -0500
> +++ mesa-7.11/src/egl/drivers/dri2/platform_wayland.c 2011-12-07 21:28:10.000000000 -0600
> @@ -734,17 +734,25 @@ drm_handle_device(void *data, struct wl_
> {
> struct dri2_egl_display *dri2_dpy = data;
> drm_magic_t magic;
> +#ifdef O_CLOEXEC
> + int flags = O_RDWR | O_CLOEXEC;
> +#else
> + int flags = O_RDWR;
> +#endif
>
> dri2_dpy->device_name = strdup(device);
> if (!dri2_dpy->device_name)
> return;
>
> - dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR);
> + dri2_dpy->fd = open(dri2_dpy->device_name, flags);
> if (dri2_dpy->fd == -1) {
> _eglLog(_EGL_WARNING, "wayland-egl: could not open %s (%s)",
> dri2_dpy->device_name, strerror(errno));
> return;
> }
> +#ifndef O_CLOEXEC
> + fcntl(dri2_dpy->fd, F_SETFD, fcntl(dri2_dpy->fd, F_GETFD) | FD_CLOEXEC);
> +#endif
>
I'd do something like
#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 >= 0)
fcntl(dri2_dpy->fd, F_SETFD, fcntl(dri2_dpy->fd, F_GETFD) | FD_CLOEXEC);
}
if (dri2_dpy->fd == -1) {
_eglLog(...);
return;
so it still works if the build environment has O_CLOEXEC but the kernel
doesn't support it at runtime.
Cheers,
Julien
Reply to: