From bdbb26378da91e541f2fe2b3e827d9f6ed11f4a8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 20 Nov 2013 09:12:36 -0800 Subject: Use O_TMPFILE if available Signed-off-by: Keith Packard Reviewed-by: Adam Jackson --- src/xshmfence.c | 14 ++++++++++---- src/xshmfenceint.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/xshmfence.c b/src/xshmfence.c index ecf2f4a..ed2b4c4 100644 --- a/src/xshmfence.c +++ b/src/xshmfence.c @@ -97,7 +97,6 @@ xshmfence_reset(struct xshmfence *f) __sync_bool_compare_and_swap(&f->v, 1, 0); } - /** * xshmfence_alloc_shm: * @@ -111,12 +110,19 @@ int xshmfence_alloc_shm(void) { char template[] = SHMDIR "/shmfd-XXXXXX"; - int fd = mkstemp(template); + int fd; +#ifdef O_TMPFILE + fd = open(SHMDIR, O_TMPFILE|O_RDWR|O_CLOEXEC|O_EXCL, 0666); if (fd < 0) +#endif + { + fd = mkstemp(template); + if (fd < 0) return fd; - unlink(template); - ftruncate(fd, sizeof (int32_t)); + unlink(template); + } + ftruncate(fd, sizeof (struct xshmfence)); return fd; } diff --git a/src/xshmfenceint.h b/src/xshmfenceint.h index e7b8b2a..66862d0 100644 --- a/src/xshmfenceint.h +++ b/src/xshmfenceint.h @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include "xshmfence.h" -- cgit v1.2.1