summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-11-20 09:12:36 -0800
committerKeith Packard <keithp@keithp.com>2013-11-20 14:13:08 -0800
commitbdbb26378da91e541f2fe2b3e827d9f6ed11f4a8 (patch)
treecfa1d4388f471208be26eb30fa811cdb8b496128
parentc17583d05872e4d9fb39af1a9963dc3738556b27 (diff)
downloadxorg-lib-libxshmfence-bdbb26378da91e541f2fe2b3e827d9f6ed11f4a8.tar.gz
Use O_TMPFILE if available
Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
-rw-r--r--src/xshmfence.c14
-rw-r--r--src/xshmfenceint.h2
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 <unistd.h>
#include <sys/syscall.h>
#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <errno.h>
#include <values.h>
#include "xshmfence.h"