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 <cp.michael@samsung.com>
This commit is contained in:
Chris Michael 2014-05-09 07:58:22 +01:00
parent 6994cb2a86
commit 8c86148a7b
1 changed files with 21 additions and 6 deletions

View 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)
{