diff options
author | Jan Beich <jbeich@FreeBSD.org> | 2017-07-07 13:57:56 +0000 |
---|---|---|
committer | Jan Beich <jbeich@FreeBSD.org> | 2019-08-03 21:54:26 +0000 |
commit | 51d4b7eafef091bd77c59777537e762fe3e586a8 (patch) | |
tree | 565bc100d5e1ef6c9c42283ba03761d672ca8965 | |
parent | 87a66f2eae8016a62d1b29e38160ed38de3144ef (diff) | |
download | xorg-lib-libxshmfence-51d4b7eafef091bd77c59777537e762fe3e586a8.tar.gz |
alloc: prefer atomic close-on-exec without O_TMPFILE as well
Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/xshmfence_alloc.c | 16 |
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) { |