libstore: move daemon protocol struct out of Settings
we'll use this to create a registry of protocols the system understands. also use this struct during connection setup to make that simpler later. Change-Id: Ifa481fea7ea2efa2a1f1be4d81076a9e022d24f9
This commit is contained in:
@@ -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<DaemonSocketPath> nixDaemonSockets_;
|
||||
std::list<daemon::Protocol> nixDaemonSockets_;
|
||||
|
||||
unsigned int getDefaultCores();
|
||||
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
/**
|
||||
* Socket paths a client should connect to, in order of decreasing preference.
|
||||
*/
|
||||
const std::list<DaemonSocketPath> & nixDaemonSockets() const
|
||||
const std::list<daemon::Protocol> & nixDaemonSockets() const
|
||||
{
|
||||
return nixDaemonSockets_;
|
||||
}
|
||||
|
||||
@@ -59,23 +59,26 @@ std::string UDSRemoteStore::getUri()
|
||||
}
|
||||
}
|
||||
|
||||
static void connectToFirstAvailableSocket(AutoCloseFD & sockFD, const std::list<Path> & paths)
|
||||
static void connectToFirstAvailableSocket(AutoCloseFD & sockFD, const std::list<daemon::Protocol> & 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<Result<ref<RemoteStore::Connection>>> UDSRemoteStore::openConnection()
|
||||
@@ -85,24 +88,22 @@ try {
|
||||
/* Connect to a daemon that does the privileged work for us. */
|
||||
conn->fd = createUnixDomainSocket();
|
||||
|
||||
std::list<Path> candidates;
|
||||
std::list<daemon::Protocol> 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<std::list<std::string>>(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<std::list<Path>>();
|
||||
candidates = settings.nixDaemonSockets();
|
||||
}
|
||||
|
||||
connectToFirstAvailableSocket(conn->fd, candidates);
|
||||
|
||||
+2
-2
@@ -340,7 +340,7 @@ static std::pair<TrustedFlag, std::string> authPeer(const PeerInfo & peer)
|
||||
|
||||
static kj::Promise<Result<void>> daemonLoopForSocket(
|
||||
const Path & self,
|
||||
const Settings::DaemonSocketPath & socket,
|
||||
const daemon::Protocol & socket,
|
||||
AutoCloseFD & fdSocket,
|
||||
std::optional<TrustedFlag> forceTrustClientOpt
|
||||
)
|
||||
@@ -437,7 +437,7 @@ try {
|
||||
return *tmp;
|
||||
}();
|
||||
|
||||
std::list<std::pair<Settings::DaemonSocketPath, AutoCloseFD>> sockets;
|
||||
std::list<std::pair<daemon::Protocol, AutoCloseFD>> sockets;
|
||||
for (auto & socket : settings.nixDaemonSockets()) {
|
||||
createDirs(dirOf(socket.path));
|
||||
sockets.emplace_back(socket, createUnixDomainSocket(socket.path, 0666));
|
||||
|
||||
Reference in New Issue
Block a user