From: Matt Whitlock Date: Sun, 2 Oct 2016 03:49:45 +0000 (-0400) Subject: gallium/winsys: replace calls to dup(2) with fcntl(F_DUPFD_CLOEXEC) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=42ed8a6c9ccfb8b6b632c3be90fb03d292f53d25;p=mesa.git gallium/winsys: replace calls to dup(2) with fcntl(F_DUPFD_CLOEXEC) Without this fix, duplicated file descriptors leak into child processes. See commit aaac913e901229d11a1894f6aaf646de6b1a542c for one instance where the same fix was employed. Cc: Signed-off-by: Matt Whitlock Reviewed-by: Nicolai Hähnle --- diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c index f90572f2f48..cc9dfa7f764 100644 --- a/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_winsys.c @@ -1,5 +1,6 @@ #include #include +#include #include "pipe/p_context.h" #include "pipe/p_state.h" #include "util/u_format.h" @@ -91,7 +92,7 @@ nouveau_drm_screen_create(int fd) * nouveau_device_wrap does not close the fd in case of a device * creation error. */ - dupfd = dup(fd); + dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 3); ret = nouveau_drm_new(dupfd, &drm); if (ret) diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c index 16e4408a9a7..c7ceee250b8 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifndef RADEON_INFO_ACTIVE_CU_COUNT @@ -751,7 +752,7 @@ radeon_drm_winsys_create(int fd, radeon_screen_create_t screen_create) return NULL; } - ws->fd = dup(fd); + ws->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3); if (!do_winsys_init(ws)) goto fail1; diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c index 74c77c54e84..d0bfcd728bf 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen.c +++ b/src/gallium/winsys/svga/drm/vmw_screen.c @@ -39,6 +39,7 @@ #endif #include #include +#include static struct util_hash_table *dev_hash = NULL; @@ -88,7 +89,7 @@ vmw_winsys_create( int fd ) vws->device = stat_buf.st_rdev; vws->open_count = 1; - vws->ioctl.drm_fd = dup(fd); + vws->ioctl.drm_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3); vws->base.have_gb_dma = TRUE; vws->base.need_to_rebind_resources = FALSE; diff --git a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c index c5434adbb43..23fe8e7b9cf 100644 --- a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c +++ b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c @@ -22,6 +22,7 @@ */ #include +#include #include "vc4_drm_public.h" @@ -30,5 +31,5 @@ struct pipe_screen * vc4_drm_screen_create(int fd) { - return vc4_screen_create(dup(fd)); + return vc4_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3)); } diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c index 11385b2faae..86e0470e682 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c @@ -867,7 +867,7 @@ virgl_drm_screen_create(int fd) virgl_screen(pscreen)->refcnt++; } else { struct virgl_winsys *vws; - int dup_fd = dup(fd); + int dup_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3); vws = virgl_drm_winsys_create(dup_fd);