[PATCH wayland v3 1/2] Extend WAYLAND_DISPLAY and name parameter semantics to support absolute paths.
Davide Bettio
davide.bettio at ispirata.com
Thu Aug 6 04:45:31 PDT 2015
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").
Signed-off-by: Davide Bettio <davide.bettio at ispirata.com>
---
doc/man/wl_display_connect.xml | 8 ++++----
src/wayland-client.c | 36
++++++++++++++++++++++++------------
src/wayland-server.c | 23 ++++++++++++++++++-----
3 files changed, 46 insertions(+), 21 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 09c594a..7c47c79 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -753,34 +753,46 @@ connect_to_socket(const char *name)
const char *runtime_dir;
int name_size, fd;
+ if (name == NULL)
+ name = getenv("WAYLAND_DISPLAY");
+ if (name == NULL)
+ name = "wayland-0";
+
runtime_dir = getenv("XDG_RUNTIME_DIR");
- if (!runtime_dir) {
- wl_log("error: XDG_RUNTIME_DIR not set in the environment.\n");
+ if (!runtime_dir && (name[0] != '/')) {
+ wl_log("error: WAYLAND_DISPLAY either not set to an absolute path or
XDG_RUNTIME_DIR not set in the environment.\n");
/* to prevent programs reporting
* "failed to create display: Success" */
errno = ENOENT;
return -1;
}
- if (name == NULL)
- name = getenv("WAYLAND_DISPLAY");
- if (name == NULL)
- name = "wayland-0";
-
fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
if (fd < 0)
return -1;
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 %i bytes\n", runtime_dir, name, (int)
sizeof(addr.sun_path));
+ } else {
+ wl_log("error: socket path \"%s\" plus null terminator"
+ " exceeds %i bytes\n", name, (int) sizeof(addr.sun_path));
+ }
close(fd);
/* to prevent programs reporting
* "failed to add socket: Success" */
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 0f04f66..fa2ad85 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1109,15 +1109,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 %i bytes\n", runtime_dir,
name, (int) sizeof(s->addr.sun_path));
+ } else {
+ wl_log("error: socket path \"%s\" plus null terminator"
+ " exceeds %i bytes\n", name, (int) sizeof(s->addr.sun_path));
+ }
*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