[PATCH 2/7] Locate directory for shared memory files at configure time

Keith Packard keithp at keithp.com
Wed Nov 20 11:55:56 PST 2013


Signed-off-by: Keith Packard <keithp at keithp.com>
---
 configure.ac    | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/xshmfence.c |  6 +++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 2780ac5..02359e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,49 @@ dnl Allow checking code with lint, sparse, etc.
 XORG_WITH_LINT
 LINT_FLAGS="${LINT_FLAGS} ${FONTENC_CFLAGS}"
 		  
+dnl
+dnl Locate a suitable tmp file system for creating shared memeory files
+dnl
+
+AC_ARG_WITH(shared-memory-dir, AS_HELP_STRING([--with-shared-memory-dir=PATH], [Path to directory in a world-writable temporary directory for anonymous shared memory (default: auto)]),
+[],
+[with_shared_memory_dir=yes])
+
+shmdirs="/run/shm /var/tmp /tmp"
+
+case x"$with_shared_memory_dir" in
+xyes)
+	for dir in $shmdirs; do
+		case x"$with_shared_memory_dir" in
+		xyes)
+			echo Checking temp dir "$dir"
+			if test -d "$dir"; then
+				with_shared_memory_dir="$dir"
+			fi
+			;;
+		esac
+	done
+	;;
+x/*)
+	;;
+xno)
+	;;
+*)
+	AC_MSG_ERROR([Invalid directory specified for --with-shared-memory-dir: $with_shared_memory_dir])
+	;;
+esac
+
+case x"$with_shared_memory_dir" in
+xyes)
+	AC_MSG_ERROR([No directory found for shared memory temp files.])
+	;;
+xno)
+	;;
+*)
+	AC_DEFINE_UNQUOTED(SHMDIR, ["$with_shared_memory_dir"], [Directory for shared memory temp files])
+	;;
+esac
+
 XORG_RELEASE_VERSION
 XORG_CHANGELOG
 
diff --git a/src/xshmfence.c b/src/xshmfence.c
index 83049de..ecf2f4a 100644
--- a/src/xshmfence.c
+++ b/src/xshmfence.c
@@ -20,6 +20,10 @@
  * OF THIS SOFTWARE.
  */
 
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "xshmfenceint.h"
 
 struct xshmfence {
@@ -106,7 +110,7 @@ xshmfence_reset(struct xshmfence *f)
 int
 xshmfence_alloc_shm(void)
 {
-	char	template[] = "/run/shm/shmfd-XXXXXX";
+	char	template[] = SHMDIR "/shmfd-XXXXXX";
 	int	fd = mkstemp(template);
 
 	if (fd < 0)
-- 
1.8.4.2



More information about the xorg-devel mailing list