diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c index 5e88d966ad..360c489805 100644 --- a/gdk/wayland/gdkdisplay-wayland.c +++ b/gdk/wayland/gdkdisplay-wayland.c @@ -22,7 +22,9 @@ #include #include #include +#include #include +#include #include #include "gdkwayland.h" @@ -928,27 +930,24 @@ create_shm_pool (struct wl_shm *shm, size_t *buf_length, void **data_out) { - char *filename; struct wl_shm_pool *pool; - int fd; + int ret, fd; void *data; - filename = g_strconcat (g_get_tmp_dir (), G_DIR_SEPARATOR_S, "wayland-shm-XXXXXX", NULL); - fd = mkstemp (filename); - if (fd < 0) + ret = syscall (SYS_memfd_create, "gdk-wayland", MFD_CLOEXEC); + + if (ret < 0) { - g_critical (G_STRLOC ": Unable to create temporary file (%s): %s", - filename, g_strerror (errno)); - g_free (filename); + g_critical (G_STRLOC ": creating shared memory file failed: %s", + g_strerror (-ret)); return NULL; } - unlink (filename); + + fd = ret; if (ftruncate (fd, size) < 0) { - g_critical (G_STRLOC ": Truncating temporary file (%s) failed: %s", - filename, g_strerror (errno)); - g_free (filename); + g_critical (G_STRLOC ": Truncating shared memory file failed: %m"); close (fd); return NULL; } @@ -957,9 +956,7 @@ create_shm_pool (struct wl_shm *shm, if (data == MAP_FAILED) { - g_critical (G_STRLOC ": mmap'ping temporary file (%s) failed: %s", - filename, g_strerror (errno)); - g_free (filename); + g_critical (G_STRLOC ": mmap'ping shared memory file failed: %m"); close (fd); return NULL; } @@ -967,7 +964,6 @@ create_shm_pool (struct wl_shm *shm, pool = wl_shm_create_pool (shm, fd, size); close (fd); - g_free (filename); *data_out = data; *buf_length = size;