Restructured for systemd socket activation.
Makes it easier to drop this step later, by returning early.
---
 src/wayland-server.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index fb07a01..9ac0a71 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1292,11 +1292,30 @@ get_socket_lock(struct wl_socket *socket)
        return fd_lock;
 }
 
+static int
+init_socket(struct wl_socket *s, int name_size)
+{
+       socklen_t size;
+
+       size = offsetof (struct sockaddr_un, sun_path) + name_size;
+       if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
+               wl_log("bind() failed with error: %m\n");
+               return -1;
+       }
+
+       if (listen(s->fd, 1) < 0) {
+               wl_log("listen() failed with error: %m\n");
+               unlink(s->addr.sun_path);
+               return -1;
+       }
+
+       return 0;
+}
+
 WL_EXPORT int
 wl_display_add_socket(struct wl_display *display, const char *name)
 {
        struct wl_socket *s;
-       socklen_t size;
        int name_size;
        const char *runtime_dir;
 
@@ -1349,20 +1368,7 @@ wl_display_add_socket(struct wl_display *display, const 
char *name)
                free(s);
                return -1;
        }
-
-       size = offsetof (struct sockaddr_un, sun_path) + name_size;
-       if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
-               wl_log("bind() failed with error: %m\n");
-               close(s->fd);
-               unlink(s->lock_addr);
-               close(s->fd_lock);
-               free(s);
-               return -1;
-       }
-
-       if (listen(s->fd, 1) < 0) {
-               wl_log("listen() failed with error: %m\n");
-               unlink(s->addr.sun_path);
+       if (init_socket(s, name_size) < 0) {
                close(s->fd);
                unlink(s->lock_addr);
                close(s->fd_lock);
-- 
1.7.12.4

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

Reply via email to