From 6c0e7450de7419f259dd44b9e62e378265eebf15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Tue, 14 Jun 2022 16:46:14 +0200 Subject: [PATCH] Allow the gc roots daemon to use a long socket path `chdir` to the directory of the socket and only use a relative path to it to bypass the socket path length limit (like it's done in `nix::bind`, except that there's no need to fork here since we can afford changing the directory of the process) --- src/nix-find-roots/main.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nix-find-roots/main.cc b/src/nix-find-roots/main.cc index c319759a7..329353644 100644 --- a/src/nix-find-roots/main.cc +++ b/src/nix-find-roots/main.cc @@ -119,8 +119,12 @@ int main(int argc, char * * argv) struct sockaddr_un addr; addr.sun_family = AF_UNIX; - unlink(opts.socketPath.c_str()); - strcpy(addr.sun_path, opts.socketPath.c_str()); + auto socketDir = opts.socketPath.parent_path(); + auto socketFilename = opts.socketPath.filename(); + chdir(socketDir.c_str()); + + fs::remove(socketFilename); + strcpy(addr.sun_path, socketFilename.c_str()); if (bind(mySock, (struct sockaddr*) &addr, sizeof(addr)) == -1) { throw Error("Cannot bind to socket"); }