<div dir="ltr">Comments below,<br>--Jason Ekstrand<br><br><div class="gmail_extra"><div class="gmail_quote">On Wed, May 7, 2014 at 9:25 AM, Jasper St. Pierre <span dir="ltr"><<a href="mailto:jstpierre@mecheye.net" target="_blank">jstpierre@mecheye.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We'll use this to autodetect a good socket to open on.<br>
---<br>
 src/wayland-server.c | 40 +++++++++++++++++++++++++---------------<br>
 1 file changed, 25 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/wayland-server.c b/src/wayland-server.c<br>
index d0fd280..6bc8dc3 100644<br>
--- a/src/wayland-server.c<br>
+++ b/src/wayland-server.c<br>
@@ -1039,11 +1039,9 @@ get_socket_lock(struct wl_socket *socket)<br>
        return fd_lock;<br>
 }<br>
<br>
-WL_EXPORT int<br>
-wl_display_add_socket(struct wl_display *display, const char *name)<br>
+static int<br>
+open_socket_for_display_name(struct wl_socket *s, const char *name)<br></blockquote><div><br>Perhaps, this should be named differently.  How about 
wl_socket_try_lock.  The problem is that it doesn't really open the 
socket (assuming I put this and the previous patch together correctly in
 my head).<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 {<br>
-       struct wl_socket *s;<br>
-       socklen_t size;<br>
        int name_size;<br>
        const char *runtime_dir;<br>
<br>
@@ -1057,15 +1055,6 @@ wl_display_add_socket(struct wl_display *display, const char *name)<br>
                return -1;<br>
        }<br>
<br>
-       s = malloc(sizeof *s);<br>
-       if (s == NULL)<br>
-               return -1;<br>
-<br>
-       if (name == NULL)<br>
-               name = getenv("WAYLAND_DISPLAY");<br>
-       if (name == NULL)<br>
-               name = "wayland-0";<br>
-<br>
        memset(&s->addr, 0, sizeof s->addr);<br>
        s->addr.sun_family = AF_LOCAL;<br>
        name_size = snprintf(s->addr.sun_path, sizeof s->addr.sun_path,<br>
@@ -1075,7 +1064,6 @@ wl_display_add_socket(struct wl_display *display, const char *name)<br>
        if (name_size > (int)sizeof s->addr.sun_path) {<br>
                wl_log("error: socket path \"%s/%s\" plus null terminator"<br>
                       " exceeds 108 bytes\n", runtime_dir, name);<br>
-               free(s);<br>
                /* to prevent programs reporting<br>
                 * "failed to add socket: Success" */<br>
                errno = ENAMETOOLONG;<br></blockquote><div><br>Why are we filling addr structure here and doing nothing with it? Perhaps filling the addr structure should stay in wl_display_add_socket?<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

@@ -1084,6 +1072,28 @@ wl_display_add_socket(struct wl_display *display, const char *name)<br>
<br>
        s->fd_lock = get_socket_lock(s);<br>
        if (s->fd_lock < 0) {<br>
+               return -1;<br>
+       }<br></blockquote><div><br></div><div>This is right before opening the socket, so it returns with an invalid value in s->fd.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

+<br>
+       return 0;<br>
+}<br>
+<br>
+WL_EXPORT int<br>
+wl_display_add_socket(struct wl_display *display, const char *name)<br>
+{<br>
+       struct wl_socket *s;<br>
+       socklen_t size;<br>
+<br>
+       s = malloc(sizeof *s);<br>
+       if (s == NULL)<br>
+               return -1;<br>
+<br>
+       if (name == NULL)<br>
+               name = getenv("WAYLAND_DISPLAY");<br>
+       if (name == NULL)<br>
+               name = "wayland-0";<br>
+<br>
+       if (open_socket_for_display_name(s, name) < 0) {<br>
                free(s);<br>
                return -1;<br>
        }<br>
@@ -1095,7 +1105,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)<br>
                return -1;<br>
        }<br>
<br>
-       size = offsetof (struct sockaddr_un, sun_path) + name_size;<br>
+       size = offsetof (struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);<br>
        if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {<br>
                wl_log("bind() failed with error: %m\n");<br>
                close(s->fd);<br>
<span class=""><font color="#888888">--<br>
1.9.0<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div></div>