[gtk+] wayland: fix error handling for memfd_create
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] wayland: fix error handling for memfd_create
- Date: Thu, 16 Jun 2016 16:02:59 +0000 (UTC)
commit bb2ca3b94d53c009c78d0f364c41ae0220ea2c9e
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 c541a6a..9f78f29 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -1104,6 +1104,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,
@@ -1111,19 +1128,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);
-
- if (ret < 0)
- {
- g_critical (G_STRLOC ": creating shared memory file failed: %s",
- g_strerror (-ret));
- return NULL;
- }
+ fd = open_shared_memory ();
- 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]