remote_store: register for NIX_REMOTE=unix://path

This allows overriding the socket path so the daemon may be listening at
an arbitrary Unix domain socket location.

Fixes #1800
This commit is contained in:
Spencer Baugh 2018-01-14 21:20:22 -05:00
parent 0c95776c3e
commit 746f8aed86
2 changed files with 26 additions and 2 deletions

View file

@ -78,9 +78,22 @@ UDSRemoteStore::UDSRemoteStore(const Params & params)
} }
UDSRemoteStore::UDSRemoteStore(std::string socket_path, const Params & params)
: Store(params)
, LocalFSStore(params)
, RemoteStore(params)
, path(socket_path)
{
}
std::string UDSRemoteStore::getUri() std::string UDSRemoteStore::getUri()
{ {
if (path) {
return std::string("unix://") + *path;
} else {
return "daemon"; return "daemon";
}
} }
@ -98,7 +111,7 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
throw SysError("cannot create Unix domain socket"); throw SysError("cannot create Unix domain socket");
closeOnExec(conn->fd.get()); closeOnExec(conn->fd.get());
string socketPath = settings.nixDaemonSocketFile; string socketPath = path ? *path : settings.nixDaemonSocketFile;
struct sockaddr_un addr; struct sockaddr_un addr;
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
@ -721,5 +734,14 @@ void RemoteStore::Connection::processStderr(Sink * sink, Source * source)
} }
} }
static std::string uriScheme = "unix://";
static RegisterStoreImplementation regStore([](
const std::string & uri, const Store::Params & params)
-> std::shared_ptr<Store>
{
if (std::string(uri, 0, uriScheme.size()) != uriScheme) return 0;
return std::make_shared<UDSRemoteStore>(std::string(uri, uriScheme.size()), params);
});
} }

View file

@ -134,6 +134,7 @@ class UDSRemoteStore : public LocalFSStore, public RemoteStore
public: public:
UDSRemoteStore(const Params & params); UDSRemoteStore(const Params & params);
UDSRemoteStore(std::string path, const Params & params);
std::string getUri() override; std::string getUri() override;
@ -145,6 +146,7 @@ private:
}; };
ref<RemoteStore::Connection> openConnection() override; ref<RemoteStore::Connection> openConnection() override;
std::experimental::optional<std::string> path;
}; };