From c990c73d626e1bb54d0889ad33d908ea2fc0d2a9 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 6 Dec 2019 17:54:05 +0100 Subject: [PATCH] support absolute paths --- src/modules/module-protocol-native.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index d3e2775d8..09fbf2a27 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -404,19 +404,31 @@ static int init_socket_name(struct server *s, const char *name) { int name_size; const char *runtime_dir; + bool path_is_absolute; - if ((runtime_dir = getenv("XDG_RUNTIME_DIR")) == NULL) { + path_is_absolute = name[0] == '/'; + + runtime_dir = getenv("XDG_RUNTIME_DIR"); + if (runtime_dir == NULL && !path_is_absolute) { pw_log_error("server %p: XDG_RUNTIME_DIR not set in the environment", s); - return -EIO; + return -ENOENT; } s->addr.sun_family = AF_LOCAL; - name_size = snprintf(s->addr.sun_path, sizeof(s->addr.sun_path), + if (path_is_absolute) + name_size = snprintf(s->addr.sun_path, sizeof(s->addr.sun_path), + "%s", name) + 1; + else + name_size = snprintf(s->addr.sun_path, sizeof(s->addr.sun_path), "%s/%s", runtime_dir, name) + 1; if (name_size > (int) sizeof(s->addr.sun_path)) { - pw_log_error("server %p: socket path \"%s/%s\" plus null terminator exceeds 108 bytes", - s, runtime_dir, name); + if (path_is_absolute) + pw_log_error("server %p: socket path \"%s\" plus null terminator exceeds %i bytes", + s, name, (int) sizeof(s->addr.sun_path)); + else + pw_log_error("server %p: socket path \"%s/%s\" plus null terminator exceeds %i bytes", + s, runtime_dir, name, (int) sizeof(s->addr.sun_path)); *s->addr.sun_path = 0; return -ENAMETOOLONG; }