[gtk+/gtk-3-20] wayland: fix error handling for memfd_create
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-20] wayland: fix error handling for memfd_create
- Date: Thu, 4 Aug 2016 15:39:13 +0000 (UTC)
commit 30e5ddfb636c0753c7a16cf62ec69f5d126ab84d
Author: Ray Strode <rstrode redhat com>
Date: Mon May 16 10:20:10 2016 -0400
wayland: fix error handling for memfd_create
We currently use syscall() directly to invoke memfd_create,
since the function isn't available in libc headers yet.
The code, though, mishandles how errors are passed from syscall().
It assumes syscall returns the error code directly (but negative),
when in fact, syscall() uses errno.
Also, the code fails to retry on EINTR.
This commit moves the handling of memfd create to a helper function,
and changes the code to use errno and handle EINTR.
https://bugzilla.gnome.org/show_bug.cgi?id=766341
gdk/wayland/gdkdisplay-wayland.c | 31 +++++++++++++++++++++----------
1 files changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 938d47d..2824d9e 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -951,6 +951,23 @@ typedef struct _GdkWaylandCairoSurfaceData {
uint32_t scale;
} GdkWaylandCairoSurfaceData;
+static int
+open_shared_memory (void)
+{
+ int ret;
+
+ do
+ {
+ ret = syscall (__NR_memfd_create, "gdk-wayland", MFD_CLOEXEC);
+ }
+ while (ret < 0 && errno == EINTR);
+
+ if (ret < 0)
+ g_critical (G_STRLOC ": creating shared memory file failed: %m");
+
+ return ret;
+}
+
static struct wl_shm_pool *
create_shm_pool (struct wl_shm *shm,
int size,
@@ -958,19 +975,13 @@ create_shm_pool (struct wl_shm *shm,
void **data_out)
{
struct wl_shm_pool *pool;
- int ret, fd;
+ int fd;
void *data;
- ret = syscall (__NR_memfd_create, "gdk-wayland", MFD_CLOEXEC);
+ fd = open_shared_memory ();
- if (ret < 0)
- {
- g_critical (G_STRLOC ": creating shared memory file failed: %s",
- g_strerror (-ret));
- return NULL;
- }
-
- fd = ret;
+ if (fd < 0)
+ return NULL;
if (ftruncate (fd, size) < 0)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]