2020-10-11 16:01:53 +00:00
|
|
|
#include "uds-remote-store.hh"
|
2023-03-23 14:06:45 +00:00
|
|
|
#include "worker-protocol.hh"
|
2020-10-11 17:18:26 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
2020-10-11 16:01:53 +00:00
|
|
|
namespace nix {
|
2020-10-11 17:18:26 +00:00
|
|
|
|
2023-06-12 09:10:55 +00:00
|
|
|
std::string UDSRemoteStoreConfig::doc()
|
|
|
|
{
|
|
|
|
return
|
|
|
|
#include "uds-remote-store.md"
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-11 17:18:26 +00:00
|
|
|
UDSRemoteStore::UDSRemoteStore(const Params & params)
|
|
|
|
: StoreConfig(params)
|
2020-12-20 15:33:12 +00:00
|
|
|
, LocalFSStoreConfig(params)
|
|
|
|
, RemoteStoreConfig(params)
|
|
|
|
, UDSRemoteStoreConfig(params)
|
2020-10-11 17:18:26 +00:00
|
|
|
, Store(params)
|
|
|
|
, LocalFSStore(params)
|
|
|
|
, RemoteStore(params)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UDSRemoteStore::UDSRemoteStore(
|
2023-03-23 14:23:13 +00:00
|
|
|
const std::string scheme,
|
|
|
|
std::string socket_path,
|
|
|
|
const Params & params)
|
2020-10-11 17:18:26 +00:00
|
|
|
: UDSRemoteStore(params)
|
|
|
|
{
|
|
|
|
path.emplace(socket_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string UDSRemoteStore::getUri()
|
|
|
|
{
|
|
|
|
if (path) {
|
|
|
|
return std::string("unix://") + *path;
|
|
|
|
} else {
|
|
|
|
return "daemon";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-23 16:01:04 +00:00
|
|
|
void UDSRemoteStore::Connection::closeWrite()
|
|
|
|
{
|
|
|
|
shutdown(fd.get(), SHUT_WR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-11 17:18:26 +00:00
|
|
|
ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
|
|
|
|
{
|
|
|
|
auto conn = make_ref<Connection>();
|
|
|
|
|
|
|
|
/* Connect to a daemon that does the privileged work for us. */
|
2021-08-16 18:03:32 +00:00
|
|
|
conn->fd = createUnixDomainSocket();
|
2020-10-11 17:18:26 +00:00
|
|
|
|
2021-08-24 11:52:55 +00:00
|
|
|
nix::connect(conn->fd.get(), path ? *path : settings.nixDaemonSocketFile);
|
2020-10-11 17:18:26 +00:00
|
|
|
|
|
|
|
conn->from.fd = conn->fd.get();
|
|
|
|
conn->to.fd = conn->fd.get();
|
|
|
|
|
|
|
|
conn->startTime = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-23 14:06:45 +00:00
|
|
|
void UDSRemoteStore::addIndirectRoot(const Path & path)
|
|
|
|
{
|
|
|
|
auto conn(getConnection());
|
|
|
|
conn->to << WorkerProto::Op::AddIndirectRoot << path;
|
|
|
|
conn.processStderr();
|
|
|
|
readInt(conn->from);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-11 17:18:26 +00:00
|
|
|
static RegisterStoreImplementation<UDSRemoteStore, UDSRemoteStoreConfig> regUDSRemoteStore;
|
|
|
|
|
|
|
|
}
|