Signed-off-by: Jan Beich <jbe...@freebsd.org>
---
 configure.ac          |  2 +-
 src/xshmfence_alloc.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 0c98875..2d55890 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,7 +89,7 @@ AC_SUBST([XPROTO_CFLAGS])
 
 CFLAGS="$CFLAGS $XPROTO_CFLAGS"
 
-AC_CHECK_FUNCS(memfd_create)
+AC_CHECK_FUNCS(memfd_create mkostemp)
 
 AC_CHECK_DECLS([__NR_memfd_create], [], [], [[#include <asm/unistd.h>]])
 
diff --git a/src/xshmfence_alloc.c b/src/xshmfence_alloc.c
index 05cf953..427335f 100644
--- a/src/xshmfence_alloc.c
+++ b/src/xshmfence_alloc.c
@@ -26,6 +26,8 @@
 
 #include "xshmfenceint.h"
 
+#include <fcntl.h>
+
 #if !HAVE_MEMFD_CREATE
 #if HAVE_DECL___NR_MEMFD_CREATE
 #include <asm/unistd.h>
@@ -79,10 +81,21 @@ xshmfence_alloc_shm(void)
                if (fd < 0)
 #endif
                {
+#ifdef HAVE_MKOSTEMP
+                       fd = mkostemp(template, O_CLOEXEC);
+#else
                        fd = mkstemp(template);
+#endif
                        if (fd < 0)
                                return fd;
                        unlink(template);
+#ifndef HAVE_MKOSTEMP
+                       int flags = fcntl(fd, F_GETFD);
+                       if (flags != -1) {
+                               flags |= FD_CLOEXEC;
+                               (void) fcntl(fd, F_SETFD, &flags);
+                       }
+#endif
                }
        }
        if (ftruncate(fd, sizeof (struct xshmfence)) < 0) {
_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to