[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").
Davide Bettio
davide.bettio at ispirata.com
Tue Mar 3 04:49:53 PST 2015
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)
}
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
+ name_size = snprintf(s->addr.sun_path, sizeof s->addr.sun_path,
+ "%s", name) + 1;
+
+ s->display_name = strrchr(s->addr.sun_path, '/') + 1;
+ }
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
More information about the wayland-devel
mailing list