[gtk+/gtk-3-18] wayland: use memfd_create instead of open in tmpdir
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-18] wayland: use memfd_create instead of open in tmpdir
- Date: Thu, 28 Jan 2016 03:31:13 +0000 (UTC)
commit 12d5e7d1f2a8b8b847121100b9369741a6d0ac3e
Author: Ray Strode <rstrode redhat com>
Date: Mon Jan 25 11:41:23 2016 -0500
wayland: use memfd_create instead of open in tmpdir
The tmpdir is used for a wide assortment of things, and
can easily fill up. If it fills then desktop will start
crashing with SIGBUS errors.
This commit changes the shm pool allocation code, to use
memfd_create, instead, so the shared memory files will
be anonymous and not associated with /tmp
https://bugzilla.gnome.org/show_bug.cgi?id=761095
gdk/wayland/gdkdisplay-wayland.c | 28 ++++++++++++----------------
1 files changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index b9befbb..9f1a1aa 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -22,7 +22,9 @@
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
+#include <linux/memfd.h>
#include <sys/mman.h>
+#include <sys/syscall.h>
#include <glib.h>
#include "gdkwayland.h"
@@ -979,27 +981,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;
}
@@ -1008,9 +1007,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;
}
@@ -1018,7 +1015,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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]