diff options
Diffstat (limited to 'lib/libxshmfence/src/xshmfence_alloc.c')
-rw-r--r-- | lib/libxshmfence/src/xshmfence_alloc.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/libxshmfence/src/xshmfence_alloc.c b/lib/libxshmfence/src/xshmfence_alloc.c index f95d1885d..55cd3bd2c 100644 --- a/lib/libxshmfence/src/xshmfence_alloc.c +++ b/lib/libxshmfence/src/xshmfence_alloc.c @@ -30,6 +30,8 @@ #define __MAP_NOFAULT 0 #endif +#include <fcntl.h> + #if !HAVE_MEMFD_CREATE #if HAVE_DECL___NR_MEMFD_CREATE #include <asm/unistd.h> @@ -72,21 +74,39 @@ 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); if (fd < 0) #endif +#ifdef SHM_ANON + fd = shm_open(SHM_ANON, O_RDWR|O_CLOEXEC, 0600); + if (fd < 0) +#endif { #ifdef O_TMPFILE fd = open(SHMDIR, O_TMPFILE|O_RDWR|O_CLOEXEC|O_EXCL, 0666); 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) { |