[PATCH wayland 3/3] server: Add a simple API to find a good default display
Jasper St. Pierre
jstpierre at mecheye.net
Wed May 7 19:07:31 PDT 2014
On Wed, May 7, 2014 at 9:31 PM, Jason Ekstrand <jason at jlekstrand.net> wrote:
>
>
>
> On Wed, May 7, 2014 at 9:25 AM, Jasper St. Pierre <jstpierre at mecheye.net>wrote:
>
>> This allows compositors to easily select a good display to listen on.
>> ---
>> src/wayland-server.c | 23 +++++++++++++++++++++++
>> src/wayland-server.h | 2 ++
>> 2 files changed, 25 insertions(+)
>>
>> diff --git a/src/wayland-server.c b/src/wayland-server.c
>> index 6bc8dc3..5624199 100644
>> --- a/src/wayland-server.c
>> +++ b/src/wayland-server.c
>> @@ -1078,6 +1078,29 @@ open_socket_for_display_name(struct wl_socket *s,
>> const char *name)
>> return 0;
>> }
>>
>> +WL_EXPORT char *
>> +wl_choose_default_display(void)
>>
>
> I mentioned this on IRC, but this seems like an awkward name. Perhaps
> something like wl_display_choose_default_name? See also below.
>
>
>> +{
>> + struct wl_socket s = { 0 };
>> + int displayno = 0;
>> + char display_name[16] = "";
>> +
>> + /* A reasonable number of maximum default sockets. If
>> + * you need more than this, set WAYLAND_DISPLAY explicitly. */
>> + const int MAX_DISPLAYNO = 32;
>> +
>> + do {
>> + snprintf(display_name, sizeof display_name, "wayland-%d",
>> displayno);
>> + if (open_socket_for_display_name(&s, display_name) >= 0) {
>> + close(s->fd_lock);
>> + return strdup(display_name);
>>
>
> We have a race condition here. If two compositors start up at the same
> time, it's possible that wl_choose_default_display will return "wayland-1"
> but then, before we get a chance to actually re-lock and connect to it,
> some other compositor opens it. Honestly, this probably isn't going to be
> a huge problem in practice. However, we may want to re-think the API a bit.
>
> One option would be to do the enumeration in wl_display_add_socket if the
> given name is NULL. This is a small API break, but all it changes is "if
> name==NULL and WAYLAND_DISPLAY is not set and wayland-0 is taken, fail" to
> "if name==NULL and WAYLAND_DISPLAY is not set and wayland-0 is taken, try
> wayland-1 etc.". It slightly changes default behavior, but I don't really
> see why failing on wayland-0 being taken is a good thing.
>
This was my initial approach, but then there's no way for a compositor to
know which display name was chosen, so it can set WAYLAND_DISPLAY. We could
save the name we used in the wl_display, if you'd prefer that.
> Thanks,
> --Jason Ekstrand
>
>
>> + }
>> + } while (displayno++ < MAX_DISPLAYNO);
>> +
>> + errno = EINVAL;
>> + return NULL;
>> +}
>> +
>> WL_EXPORT int
>> wl_display_add_socket(struct wl_display *display, const char *name)
>> {
>> diff --git a/src/wayland-server.h b/src/wayland-server.h
>> index 7fc5b47..c9834f1 100644
>> --- a/src/wayland-server.h
>> +++ b/src/wayland-server.h
>> @@ -88,6 +88,8 @@ struct wl_listener *wl_event_loop_get_destroy_listener(
>> struct wl_event_loop *loop,
>> wl_notify_func_t notify);
>>
>> +char *wl_choose_default_socket(void);
>> +
>> struct wl_display *wl_display_create(void);
>> void wl_display_destroy(struct wl_display *display);
>> struct wl_event_loop *wl_display_get_event_loop(struct wl_display
>> *display);
>> --
>> 1.9.0
>>
>> _______________________________________________
>> wayland-devel mailing list
>> wayland-devel at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>>
>
>
--
Jasper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20140507/82bb42c2/attachment.html>
More information about the wayland-devel
mailing list