[PATCH 3/7] Use O_TMPFILE if available
Keith Packard
keithp at keithp.com
Wed Nov 20 11:55:57 PST 2013
Signed-off-by: Keith Packard <keithp at keithp.com>
---
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 <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"
--
1.8.4.2
More information about the xorg-devel
mailing list