aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorjade <lix@jade.fyi>2024-05-30 14:56:57 +0000
committerGerrit Code Review <gerrit@lix-systems>2024-05-30 14:56:57 +0000
commit53d40888ffe8238ab5baf6a9d1a7481c29e9c65d (patch)
treeb24c16c56a01ce8b1b11a71834e272692a44e65b /src/libutil
parent3d78b4847eb6fff3b2872f991751b8caa2ae4c5a (diff)
parent26b3a1b9ce526b14d92666695c2b712b2d025d15 (diff)
Merge "unix-domain-socket.cc: add comment explaining why bindConnectProcHelper" into main
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/unix-domain-socket.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libutil/unix-domain-socket.cc b/src/libutil/unix-domain-socket.cc
index a9a2a415a..a6e46ca50 100644
--- a/src/libutil/unix-domain-socket.cc
+++ b/src/libutil/unix-domain-socket.cc
@@ -37,6 +37,17 @@ AutoCloseFD createUnixDomainSocket(const Path & path, mode_t mode)
return fdSocket;
}
+/**
+ * Workaround for the max length of Unix socket names being between 102
+ * (darwin) and 108 (Linux), which is extremely short. This limitation is
+ * caused by historical restrictions on sizeof(struct sockaddr):
+ * https://unix.stackexchange.com/a/367012.
+ *
+ * Our solution here is to start a process inheriting the socket, chdir into
+ * the directory of the socket, then connect with just the filename. This is
+ * rather silly but it works around working directory being process-wide state,
+ * and is as clearly sound as possible.
+ */
static void bindConnectProcHelper(
std::string_view operationName, auto && operation,
int fd, const std::string & path)