mirror of
https://github.com/NixOS/nix.git
synced 2025-04-15 13:47:34 +00:00
Add convenience function for connecting to a Unix domain socket
This commit is contained in:
parent
bbfe39ef27
commit
6f2ec5f359
@ -84,9 +84,7 @@ 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(toSocket(conn->fd.get()), path);
|
||||
conn->fd = nix::connect(path);
|
||||
|
||||
conn->from.fd = conn->fd.get();
|
||||
conn->to.fd = conn->fd.get();
|
||||
|
@ -9,6 +9,8 @@
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
@ -80,4 +82,9 @@ void bind(Socket fd, const std::string & path);
|
||||
*/
|
||||
void connect(Socket fd, const std::string & path);
|
||||
|
||||
/**
|
||||
* Connect to a Unix domain socket.
|
||||
*/
|
||||
AutoCloseFD connect(const std::filesystem::path & path);
|
||||
|
||||
}
|
||||
|
@ -114,4 +114,11 @@ void connect(Socket fd, const std::string & path)
|
||||
bindConnectProcHelper("connect", ::connect, fd, path);
|
||||
}
|
||||
|
||||
AutoCloseFD connect(const std::filesystem::path & path)
|
||||
{
|
||||
auto fd = createUnixDomainSocket();
|
||||
nix::connect(toSocket(fd.get()), path);
|
||||
return fd;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user