aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-05-29 15:56:32 -0700
committerJade Lovelace <lix@jade.fyi>2024-05-29 19:50:04 -0700
commit26b3a1b9ce526b14d92666695c2b712b2d025d15 (patch)
treef5f078d9248359a22bdbc9b90bba5b10db28e075 /src
parent562ff516ab27b8e98490646dd30ac96e7e2c36bb (diff)
unix-domain-socket.cc: add comment explaining why bindConnectProcHelper
We reviewed this code a while ago, and we neglected to get a comment in saying why it's Like This at the time. Let's fix that, since it is code that looks very absurd at first glance. Change-Id: Ib67b49605ef9ef1c84ecda1db16be74fc9105398
Diffstat (limited to 'src')
-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)