[PATCH wayland] Require WAYLAND_DISPLAY to be set instead of using wayland-0 as the default

Dima Ryazanov dima at gmail.com
Fri Aug 14 00:13:07 PDT 2015


So, it seems like pretty much everyone agrees with this change. Could we
actually get it in for the 1.9 release?

On Thu, Aug 13, 2015 at 4:47 AM, Ryo Munakata <ryomnktml at gmail.com> wrote:

> On Wed, 12 Aug 2015 19:34:31 -0700
> Dima Ryazanov <dima at gmail.com> wrote:
>
> Hi Dima.
>
> Reviewed-by: Ryo Munakata <ryomnktml at gmail.com>
>
> Thanks.
>
> > Although defaulting to wayland-0 seems convenient, it has an undesirable
> > side effect: clients may unintentionally connect to the wrong compositor.
> > Generally, it's safer to fail instead. Here's a real example:
> >
> > In Fedora 22, Gtk+ prefers Wayland over X11, though the default session
> is still
> > a normal X11 Gnome session. When you launch a Gtk+ app, it will try
> Wayland,
> > fail, then try X11, and succesfully start up. That works fine.
> >
> > Now suppose you launch Weston while running the Gnome session. Suddenly,
> all
> > of the Gtk+ apps launched from Gnome will show up inside Weston instead.
> > That's unexpected. There's also no good way to prevent that from
> happening
> > (other than perhaps setting WAYLAND_DISPLAY to an invalid value when
> launching
> > an app).
> >
> > Not using wayland-0 as the default will solve that problem: an app
> launched
> > from the X11 Gnome session will use the X11 backend regardless of whether
> > there's a wayland compositor running at the same time.
> >
> > Everything else should work as before. The compositor already sets
> > the WAYLAND_DISPLAY when starting the session, so the lack of the
> default value
> > should not make a difference to the user.
> >
> > Signed-off-by: Dima Ryazanov <dima at gmail.com>
> > Acked-by: Pekka Paalanen <ppaalanen at gmail.com>
> > Acked-by: Giulio Camuffo <giuliocamuffo at gmail.com>
> > Acked-by: Daniel Stone <daniel at fooishbar.org>
> > Acked-by: Jasper St. Pierre <jstpierre at mecheye.net>
> > ---
> >  doc/man/wl_display_connect.xml    |  5 ++---
> >  doc/publican/sources/Protocol.xml |  8 ++++----
> >  src/wayland-client.c              | 10 ++++++----
> >  src/wayland-server.c              |  6 +++---
> >  4 files changed, 15 insertions(+), 14 deletions(-)
> >
> > diff --git a/doc/man/wl_display_connect.xml
> b/doc/man/wl_display_connect.xml
> > index 7e6e05c..ded3cbd 100644
> > --- a/doc/man/wl_display_connect.xml
> > +++ b/doc/man/wl_display_connect.xml
> > @@ -57,9 +57,8 @@
> >            that was previously opened by a Wayland server. The server
> socket must
> >            be placed in <envar>XDG_RUNTIME_DIR</envar> for this function
> to
> >            find it. The <varname>name</varname> argument specifies the
> name of
> > -          the socket or <constant>NULL</constant> to use the default
> (which is
> > -          <constant>"wayland-0"</constant>). The environment variable
> > -          <envar>WAYLAND_DISPLAY</envar> replaces the default value. If
> > +          the socket or <constant>NULL</constant> to use the default
> > +          (which is the value of <envar>WAYLAND_DISPLAY</envar>). If
> >            <envar>WAYLAND_SOCKET</envar> is set, this function behaves
> like
> >            <function>wl_display_connect_to_fd</function> with the
> file-descriptor
> >            number taken from the environment variable.</para>
> > diff --git a/doc/publican/sources/Protocol.xml
> b/doc/publican/sources/Protocol.xml
> > index 477063b..9464953 100644
> > --- a/doc/publican/sources/Protocol.xml
> > +++ b/doc/publican/sources/Protocol.xml
> > @@ -60,10 +60,10 @@
> >      <title>Wire Format</title>
> >      <para>
> >        The protocol is sent over a UNIX domain stream socket, where the
> endpoint
> > -      usually is named <systemitem
> class="service">wayland-0</systemitem>
> > -      (although it can be changed via
> <emphasis>WAYLAND_DISPLAY</emphasis>
> > -      in the environment).  The protocol is message-based.  A
> > -      message sent by a client to the server is called request.  A
> message
> > +      name is determined by the <emphasis>WAYLAND_DISPLAY</emphasis>
> > +      environment variable.  Its value will usually be
> > +      <systemitem class="service">wayland-0</systemitem>.  The protocol
> is message-based.
> > +      A message sent by a client to the server is called request.  A
> message
> >        from the server to a client is called event.  Every message is
> >        structured as 32-bit words, values are represented in the host's
> >        byte-order.
> > diff --git a/src/wayland-client.c b/src/wayland-client.c
> > index 09c594a..ffbca4b 100644
> > --- a/src/wayland-client.c
> > +++ b/src/wayland-client.c
> > @@ -764,8 +764,11 @@ connect_to_socket(const char *name)
> >
> >       if (name == NULL)
> >               name = getenv("WAYLAND_DISPLAY");
> > -     if (name == NULL)
> > -             name = "wayland-0";
> > +     if (name == NULL) {
> > +             wl_log("error: WAYLAND_DISPLAY not set in the
> environment.\n");
> > +             errno = ENOENT;
> > +             return -1;
> > +     }
> >
> >       fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
> >       if (fd < 0)
> > @@ -869,8 +872,7 @@ wl_display_connect_to_fd(int fd)
> >   * \return A \ref wl_display object or \c NULL on failure
> >   *
> >   * Connect to the Wayland display named \c name. If \c name is \c NULL,
> > - * its value will be replaced with the WAYLAND_DISPLAY environment
> > - * variable if it is set, otherwise display "wayland-0" will be used.
> > + * its value will be replaced with the WAYLAND_DISPLAY environment
> variable.
> >   *
> >   * \memberof wl_display
> >   */
> > diff --git a/src/wayland-server.c b/src/wayland-server.c
> > index 0f04f66..1ea53f9 100644
> > --- a/src/wayland-server.c
> > +++ b/src/wayland-server.c
> > @@ -1209,8 +1209,8 @@ wl_display_add_socket_auto(struct wl_display
> *display)
> >   * connect to Wayland display.
> >   *
> >   * If NULL is passed as name, then it would look for WAYLAND_DISPLAY env
> > - * variable for the socket name. If WAYLAND_DISPLAY is not set, then
> default
> > - * wayland-0 is used.
> > + * variable for the socket name. If WAYLAND_DISPLAY is not set, this
> function
> > + * fails and returns -1.
> >   *
> >   * The Unix socket will be created in the directory pointed to by
> environment
> >   * variable XDG_RUNTIME_DIR. If XDG_RUNTIME_DIR is not set, then this
> function
> > @@ -1235,7 +1235,7 @@ wl_display_add_socket(struct wl_display *display,
> const char *name)
> >       if (name == NULL)
> >               name = getenv("WAYLAND_DISPLAY");
> >       if (name == NULL)
> > -             name = "wayland-0";
> > +             return -1;
> >
> >       if (wl_socket_init_for_display_name(s, name) < 0) {
> >               wl_socket_destroy(s);
> > --
> > 2.4.3
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>
> --
> Ryo Munakata <ryomnktml at gmail.com>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150814/dd390e23/attachment.html>


More information about the wayland-devel mailing list