We need our own copy of the file-descriptor in each wl_display so we can
close() it on error to wake up the main-thread.

Signed-off-by: David Herrmann <[email protected]>
---
 src/wayland-client.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index c17cea3..cd2f508 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -69,7 +69,6 @@ struct wl_display {
        struct wl_connection *connection;
        int last_error;
        int fd;
-       int close_fd;
        pthread_t display_thread;
        struct wl_map objects;
        struct wl_event_queue queue;
@@ -365,7 +364,12 @@ wl_display_connect_to_fd(int fd)
 
        memset(display, 0, sizeof *display);
 
-       display->fd = fd;
+       display->fd = wl_os_dupfd_cloexec(fd, 0);
+       if (display->fd < 0) {
+               free(display);
+               return NULL;
+       }
+
        wl_map_init(&display->objects);
        wl_event_queue_init(&display->queue, display);
        wl_list_init(&display->event_queues);
@@ -416,9 +420,7 @@ wl_display_connect(const char *name)
        }
 
        display = wl_display_connect_to_fd(fd);
-       if (display)
-               display->close_fd = 1;
-
+       close(fd);
        return display;
 }
 
@@ -428,10 +430,7 @@ wl_display_disconnect(struct wl_display *display)
        wl_connection_destroy(display->connection);
        wl_map_release(&display->objects);
        wl_event_queue_release(&display->queue);
-
-       if (display->close_fd)
-               close(display->fd);
-
+       close(display->fd);
        free(display);
 }
 
-- 
1.7.12.2

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to