[PATCH libxshmfence] Prefer mkostemp(3) over open(2) or mkstemp(3).
Jung-uk Kim
jkim at FreeBSD.org
Mon Dec 9 14:37:02 PST 2013
Signed-off-by: Jung-uk Kim <jkim at FreeBSD.org>
---
configure.ac | 2 ++
src/xshmfence_alloc.c | 8 ++++++--
src/xshmfenceint.h | 1 +
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 64fb0cc..9f37ed6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,6 +84,8 @@ AC_SUBST([PTHREAD_LIBS])
AM_CONDITIONAL([FUTEX], [test x"$FUTEX" = xyes])
AM_CONDITIONAL([PTHREAD], [test x"$PTHREAD" = xyes])
+AC_CHECK_FUNC([mkostemp], AC_DEFINE(HAVE_MKOSTEMP, 1, [Use mkostemp(3)]))
+
PKG_CHECK_MODULES(XPROTO, xproto)
AC_SUBST([XPROTO_CFLAGS])
diff --git a/src/xshmfence_alloc.c b/src/xshmfence_alloc.c
index 58416cd..8c40f39 100644
--- a/src/xshmfence_alloc.c
+++ b/src/xshmfence_alloc.c
@@ -41,11 +41,15 @@ xshmfence_alloc_shm(void)
char template[] = SHMDIR "/shmfd-XXXXXX";
int fd;
-#ifdef O_TMPFILE
+#if defined(O_CLOEXEC)
+#if defined(HAVE_MKOSTEMP)
+ fd = mkostemp(template, O_CLOEXEC);
+#elif defined(O_TMPFILE)
fd = open(SHMDIR, O_TMPFILE|O_RDWR|O_CLOEXEC|O_EXCL, 0666);
- if (fd < 0)
#endif
+ if (fd < 0)
{
+#endif
fd = mkstemp(template);
if (fd < 0)
return fd;
diff --git a/src/xshmfenceint.h b/src/xshmfenceint.h
index 178cbdd..ac3904a 100644
--- a/src/xshmfenceint.h
+++ b/src/xshmfenceint.h
@@ -23,6 +23,7 @@
#ifndef _XSHMFENCEINT_H_
#define _XSHMFENCEINT_H_
+#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
--
1.8.4.3
More information about the xorg-devel
mailing list