summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/main.c b/main.c
index 7899b7b..ee72824 100644
--- a/main.c
+++ b/main.c
@@ -121,9 +121,17 @@ int get_socket_fd (const char *socketname, int as_daemon)
int fd;
struct sockaddr_un addr;
- // TODO: Re-check the documentation apropos socket name length
+ /* UNIX domain socket name lengths are limited to "sizeof(sun_path)", which
+ * varies from one system to another. A partial solution would be to call
+ * "chdir" to trim out the directory part of the socket name and use a
+ * relative path, but the file part of the socket could still be too large
+ * for sockaddr_un.
+ *
+ * It's easier to check the socket length and simply reject names that would
+ * overflow the buffer.
+ */
if (strlen(socketname) > sizeof(addr.sun_path) - 1) {
- fputs("Failed to create socket: filename too long\n", stderr);
+ fputs("Cannot create or open socket: Filename too long\n", stderr);
return -1;
}