[PATCH 1/3] Extend WAYLAND_DISPLAY and name parameter semantics to support absolute paths. For example WAYLAND_DISPLAY="/my/path/wayland-2" or connect_to_socket("/my/path/wayland-2").

Marek Chalupa mchqwerty at gmail.com
Thu Mar 5 03:15:13 PST 2015


On Tue, Mar 3, 2015 at 7:49 AM, Davide Bettio <davide.bettio at ispirata.com>
wrote:

> Signed-off-by: Davide Bettio <davide.bettio at ispirata.com>
> ---
>  doc/man/wl_display_connect.xml |  8 ++++----
>  src/wayland-client.c           | 22 +++++++++++++++++-----
>  src/wayland-server.c           | 23 ++++++++++++++++++-----
>  3 files changed, 39 insertions(+), 14 deletions(-)
>
> diff --git a/doc/man/wl_display_connect.xml
> b/doc/man/wl_display_connect.xml
> index 7e6e05c..b78c53f 100644
> --- a/doc/man/wl_display_connect.xml
> +++ b/doc/man/wl_display_connect.xml
> @@ -59,10 +59,10 @@
>            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
> -          <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>
> +          <envar>WAYLAND_DISPLAY</envar> replaces the default value, and
> eventually uses
> +          a different path too. 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>
>
>      <para><function>wl_display_connect_to_fd</function> connects to a
> Wayland
>            socket with an explicit file-descriptor. The file-descriptor is
> passed
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index 0f1405c..cc01573 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -768,14 +768,26 @@ connect_to_socket(const char *name)
>
>         memset(&addr, 0, sizeof addr);
>         addr.sun_family = AF_LOCAL;
> -       name_size =
> -               snprintf(addr.sun_path, sizeof addr.sun_path,
> -                        "%s/%s", runtime_dir, name) + 1;
> +       if (name[0] != '/') {
> +               name_size =
> +                       snprintf(addr.sun_path, sizeof addr.sun_path,
> +                                "%s/%s", runtime_dir, name) + 1;
> +       } else {
> +               /* absolute path */
> +               name_size =
> +                       snprintf(addr.sun_path, sizeof addr.sun_path,
> +                                "%s", name) + 1;
> +       }
>
>         assert(name_size > 0);
>         if (name_size > (int)sizeof addr.sun_path) {
> -               wl_log("error: socket path \"%s/%s\" plus null terminator"
> -                      " exceeds 108 bytes\n", runtime_dir, name);
> +               if (name[0] != '/') {
> +                       wl_log("error: socket path \"%s/%s\" plus null
> terminator"
> +                              " exceeds 108 bytes\n", runtime_dir, name);
> +               } else {
> +                       wl_log("error: socket path \"%s\" plus null
> terminator"
> +                              " exceeds 108 bytes\n", name);
> +               }
>                 close(fd);
>                 /* to prevent programs reporting
>                  * "failed to add socket: Success" */
> diff --git a/src/wayland-server.c b/src/wayland-server.c
> index 0558634..eefbe35 100644
> --- a/src/wayland-server.c
> +++ b/src/wayland-server.c
> @@ -1104,15 +1104,28 @@ wl_socket_init_for_display_name(struct wl_socket
> *s, const char *name)
>         }
>
>
Before the following piece of code is check for XDG_RUNTIME_DIR env
variable and if it is not set,
the function returns here (
http://cgit.freedesktop.org/wayland/wayland/tree/src/wayland-server.c#n1097
).
When absolute path is given, we don't need XDG_RUNTIME_DIR specified, so
you'd probably want to take care of it.
The same is in wayland-client.c.


>         s->addr.sun_family = AF_LOCAL;
> -       name_size = snprintf(s->addr.sun_path, sizeof s->addr.sun_path,
> -                            "%s/%s", runtime_dir, name) + 1;
> +       if (name[0] != '/') {
> +               name_size = snprintf(s->addr.sun_path, sizeof
> s->addr.sun_path,
> +                                    "%s/%s", runtime_dir, name) + 1;
>
> -       s->display_name = (s->addr.sun_path + name_size - 1) -
> strlen(name);
> +               s->display_name = (s->addr.sun_path + name_size - 1) -
> strlen(name);
> +       } else {
> +               //absolute path
>

use original C comments, please


> +               name_size = snprintf(s->addr.sun_path, sizeof
> s->addr.sun_path,
> +                                    "%s", name) + 1;
> +
> +               s->display_name = strrchr(s->addr.sun_path, '/') + 1;
>

I wonder if this is right. Until now, when you had display_name,
you knew that the socket was $XDG_RUNTIME_DIR/display_name.
Now it can be anywhere and you still have just name of it. However, this
does not look like a big deal since
s->display_name is used only in wl_display_add_socket_auto where we use our
own names.


> +       }
>
>         assert(name_size > 0);
>         if (name_size > (int)sizeof s->addr.sun_path) {
> -               wl_log("error: socket path \"%s/%s\" plus null terminator"
> -                      " exceeds 108 bytes\n", runtime_dir, name);
> +               if (name[0] != '/') {
> +                       wl_log("error: socket path \"%s/%s\" plus null
> terminator"
> +                               " exceeds 108 bytes\n", runtime_dir, name);
> +               } else {
> +                       wl_log("error: socket path \"%s\" plus null
> terminator"
> +                              " exceeds 108 bytes\n", name);
> +               }
>                 *s->addr.sun_path = 0;
>                 /* to prevent programs reporting
>                  * "failed to add socket: Success" */
> --
> 2.1.0
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>

Any tests for this patch?

Best Regards,
Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150305/d7a4e9f7/attachment-0001.html>


More information about the wayland-devel mailing list