evas-wayland-shm: Use XDG_RUNTIME_DIR if available for creating mmap'd
authorChris Michael <cp.michael@samsung.com>
Fri, 9 May 2014 06:58:22 +0000 (07:58 +0100)
committerChris Michael <cp.michael@samsung.com>
Fri, 9 May 2014 07:00:44 +0000 (08:00 +0100)
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 <cp.michael@samsung.com>
src/modules/evas/engines/wayland_shm/evas_swapper.c

index 1a879fa..87ac92d 100644 (file)
@@ -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)
      {