the very slight speedup in config setting access is not worth the maintenance overhead of conflating concers like this. the virtual inheritance scheme used for configs requires too much duplication of base class constructor arguments to be worth doing. perhaps we should get rid of all virtual inheritance of data-membered bases? Change-Id: I4acf5ceaedb4ed7476efe1114c2e065ec72d2c6d
91 lines
1.7 KiB
C++
91 lines
1.7 KiB
C++
#include "lix/libstore/uds-remote-store.hh"
|
|
#include "lix/libutil/unix-domain-socket.hh"
|
|
#include "lix/libstore/worker-protocol.hh"
|
|
|
|
#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>
|
|
|
|
|
|
namespace nix {
|
|
|
|
std::string UDSRemoteStoreConfig::doc()
|
|
{
|
|
return
|
|
#include "uds-remote-store.md"
|
|
;
|
|
}
|
|
|
|
UDSRemoteStore::UDSRemoteStore(UDSRemoteStoreConfig config)
|
|
: Store(config)
|
|
, RemoteStore(config)
|
|
, config_(std::move(config))
|
|
{
|
|
}
|
|
|
|
|
|
UDSRemoteStore::UDSRemoteStore(
|
|
const std::string scheme,
|
|
std::string socket_path,
|
|
UDSRemoteStoreConfig config)
|
|
: UDSRemoteStore(std::move(config))
|
|
{
|
|
path.emplace(socket_path);
|
|
}
|
|
|
|
|
|
std::string UDSRemoteStore::getUri()
|
|
{
|
|
if (path) {
|
|
return std::string("unix://") + *path;
|
|
} else {
|
|
return "daemon";
|
|
}
|
|
}
|
|
|
|
|
|
void UDSRemoteStore::Connection::closeWrite()
|
|
{
|
|
shutdown(fd.get(), SHUT_WR);
|
|
}
|
|
|
|
|
|
ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
|
|
{
|
|
auto conn = make_ref<Connection>();
|
|
|
|
/* Connect to a daemon that does the privileged work for us. */
|
|
conn->fd = createUnixDomainSocket();
|
|
|
|
nix::connect(conn->fd.get(), path ? *path : settings.nixDaemonSocketFile);
|
|
|
|
conn->from.fd = conn->fd.get();
|
|
conn->to.fd = conn->fd.get();
|
|
|
|
conn->startTime = std::chrono::steady_clock::now();
|
|
|
|
return conn;
|
|
}
|
|
|
|
|
|
void UDSRemoteStore::addIndirectRoot(const Path & path)
|
|
{
|
|
auto conn(getConnection());
|
|
conn->to << WorkerProto::Op::AddIndirectRoot << path;
|
|
conn.processStderr();
|
|
readInt(conn->from);
|
|
}
|
|
|
|
|
|
void registerUDSRemoteStore() {
|
|
StoreImplementations::add<UDSRemoteStore, UDSRemoteStoreConfig>();
|
|
}
|
|
|
|
}
|