diff --git a/lix/libstore/globals.hh b/lix/libstore/globals.hh index 22e833cce..9440f6768 100644 --- a/lix/libstore/globals.hh +++ b/lix/libstore/globals.hh @@ -10,6 +10,13 @@ namespace nix { +namespace daemon { +struct Protocol +{ + Path path; +}; +} + typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode; void to_json(JSON & j, const SandboxMode & e); @@ -63,14 +70,7 @@ const uint32_t maxIdsPerBuild = class Settings : public Config { -public: - struct DaemonSocketPath - { - Path path; - }; - -private: - std::list nixDaemonSockets_; + std::list nixDaemonSockets_; unsigned int getDefaultCores(); @@ -128,7 +128,7 @@ public: /** * Socket paths a client should connect to, in order of decreasing preference. */ - const std::list & nixDaemonSockets() const + const std::list & nixDaemonSockets() const { return nixDaemonSockets_; } diff --git a/lix/libstore/uds-remote-store.cc b/lix/libstore/uds-remote-store.cc index ccdff65e6..4eb8cd191 100644 --- a/lix/libstore/uds-remote-store.cc +++ b/lix/libstore/uds-remote-store.cc @@ -59,23 +59,26 @@ std::string UDSRemoteStore::getUri() } } -static void connectToFirstAvailableSocket(AutoCloseFD & sockFD, const std::list & paths) +static void connectToFirstAvailableSocket(AutoCloseFD & sockFD, const std::list & paths) { for (const auto & socket : paths) { try { - nix::connect(sockFD.get(), socket); + nix::connect(sockFD.get(), socket.path); return; } catch (SysError & e) { if (e.errNo == EACCES || e.errNo == EPERM || e.errNo == ECONNREFUSED || e.errNo == ENOENT || e.errNo == ENOTDIR || e.errNo == ENOTSOCK) { - debug("skipping socket %s: %s", socket, strerror(e.errNo)); + debug("skipping socket %s: %s", socket.path, strerror(e.errNo)); } else { throw; } } } - throw Error("could not connect to any lix socket (tried %s)", concatStringsSep(", ", paths)); + throw Error( + "could not connect to any lix socket (tried %s)", + concatMapStringsSep(", ", paths, [](auto & s) { return s.path; }) + ); } kj::Promise>> UDSRemoteStore::openConnection() @@ -85,24 +88,22 @@ try { /* Connect to a daemon that does the privileged work for us. */ conn->fd = createUnixDomainSocket(); - std::list candidates; + std::list candidates; if (path) { if (config().protocol == "any") { - candidates.emplace_back(*path + LEGACY_SOCKET_COMBINED); + candidates.push_back(daemon::Protocol{*path + LEGACY_SOCKET_COMBINED}); } else { for (const auto & proto : tokenizeString>(config().protocol.get(), " ,")) { if (proto == "legacy-combined") { - candidates.emplace_back(*path); + candidates.push_back(daemon::Protocol{*path}); } else { throw Error("can't connect to %s with unknown daemon protocol %s", *path, proto); } } } } else { - candidates = settings.nixDaemonSockets() - | std::views::transform([](auto & socket) { return socket.path; }) - | std::ranges::to>(); + candidates = settings.nixDaemonSockets(); } connectToFirstAvailableSocket(conn->fd, candidates); diff --git a/lix/nix/daemon.cc b/lix/nix/daemon.cc index b9e2cc2c5..21f973f4a 100644 --- a/lix/nix/daemon.cc +++ b/lix/nix/daemon.cc @@ -340,7 +340,7 @@ static std::pair authPeer(const PeerInfo & peer) static kj::Promise> daemonLoopForSocket( const Path & self, - const Settings::DaemonSocketPath & socket, + const daemon::Protocol & socket, AutoCloseFD & fdSocket, std::optional forceTrustClientOpt ) @@ -437,7 +437,7 @@ try { return *tmp; }(); - std::list> sockets; + std::list> sockets; for (auto & socket : settings.nixDaemonSockets()) { createDirs(dirOf(socket.path)); sockets.emplace_back(socket, createUnixDomainSocket(socket.path, 0666));