From 5074ca37ff4ed6013835bf6adb6f9e0a20935a2d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 21 Feb 2020 15:05:43 +0100 Subject: [PATCH] protocol-native: Improve errors A missing XDG_RUNTIME_DIR results in ENOENT, like on the server side. A too long name results in ENAMETOOLONG, like on the server side. When we can't find the socket, return EHOSTDOWN to make it more obvious what is going. --- src/modules/module-protocol-native/local-socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/module-protocol-native/local-socket.c b/src/modules/module-protocol-native/local-socket.c index 0c0ee2314..14e1c14e4 100644 --- a/src/modules/module-protocol-native/local-socket.c +++ b/src/modules/module-protocol-native/local-socket.c @@ -62,7 +62,7 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client, if ((runtime_dir = getenv("XDG_RUNTIME_DIR")) == NULL) { pw_log_error("connect failed: XDG_RUNTIME_DIR not set in the environment"); - res = -EIO; + res = -ENOENT; goto error; } @@ -80,13 +80,15 @@ int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client, if (name_size > (int) sizeof addr.sun_path) { pw_log_error("socket path \"%s/%s\" plus null terminator exceeds 108 bytes", runtime_dir, name); - res = -ENOSPC; - goto error_close; + res = -ENAMETOOLONG; + goto error_close; }; size = offsetof(struct sockaddr_un, sun_path) + name_size; if (connect(fd, (struct sockaddr *) &addr, size) < 0) { + if (errno == ENOENT) + errno = EHOSTDOWN; res = -errno; goto error_close; }