From 8c86148a7beac669a198e621062aded006d40da8 Mon Sep 17 00:00:00 2001 From: Chris Michael Date: Fri, 9 May 2014 07:58:22 +0100 Subject: [PATCH] evas-wayland-shm: Use XDG_RUNTIME_DIR if available for creating mmap'd buffer file. @bugfix: When we create the mmap'd file for shm buffer access, try using the XDG_RUNTIME_DIR first as the place to create the file. If that does not exist in the environment, Then fallback to using /tmp directory. Signed-off-by: Chris Michael --- .../evas/engines/wayland_shm/evas_swapper.c | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/modules/evas/engines/wayland_shm/evas_swapper.c b/src/modules/evas/engines/wayland_shm/evas_swapper.c index 1a879faece..87ac92d8e1 100644 --- a/src/modules/evas/engines/wayland_shm/evas_swapper.c +++ b/src/modules/evas/engines/wayland_shm/evas_swapper.c @@ -293,7 +293,9 @@ evas_swapper_buffer_idle_flush(Wl_Swapper *ws) static Eina_Bool _evas_swapper_shm_pool_new(Wl_Swapper *ws) { - char tmp[PATH_MAX]; + static const char tmp[] = "evas-wayland_shm-XXXXXX"; + const char *path; + char *name; size_t size; int fd = 0; @@ -308,18 +310,31 @@ _evas_swapper_shm_pool_new(Wl_Swapper *ws) /* check pool size to see if we need to realloc the pool */ if (size <= ws->pool_size) return EINA_TRUE; - /* create tmp file - * - * NB: Should this use XDG_RUNTIME_DIR ?? */ - strcpy(tmp, "/tmp/evas-wayland_shm-XXXXXX"); + /* create tmp file, trying to use XDG_RUNTIME if set */ + if ((path = getenv("XDG_RUNTIME_DIR"))) + { + if ((name = malloc(strlen(path) + sizeof(tmp)))) + strcpy(name, path); + } + else + { + if ((name = malloc(strlen("/tmp") + sizeof(tmp)))) + strcpy(name, "/tmp"); + } + + if (!name) return EINA_FALSE; + + strcat(name, tmp); /* try to create the tmp file */ - if ((fd = mkstemp(tmp)) < 0) + if ((fd = mkstemp(name)) < 0) { ERR("Could not create temporary file."); return EINA_FALSE; } + free(name); + /* try to truncate the tmp file to requested size */ if (ftruncate(fd, size) < 0) {