summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac2
-rw-r--r--src/xshmfence_alloc.c16
2 files changed, 17 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 94c27b3..5636cb8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,7 +91,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..cba99a3 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>
@@ -68,6 +70,9 @@ xshmfence_alloc_shm(void)
{
char template[] = SHMDIR "/shmfd-XXXXXX";
int fd;
+#ifndef HAVE_MKOSTEMP
+ int flags;
+#endif
#if HAVE_MEMFD_CREATE
fd = memfd_create("xshmfence", MFD_CLOEXEC|MFD_ALLOW_SEALING);
@@ -79,10 +84,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
+ flags = fcntl(fd, F_GETFD);
+ if (flags != -1) {
+ flags |= FD_CLOEXEC;
+ fcntl(fd, F_SETFD, &flags);
+ }
+#endif
}
}
if (ftruncate(fd, sizeof (struct xshmfence)) < 0) {