mirror of
https://github.com/NixOS/nix
synced 2025-07-01 00:07:58 +02:00
makeJSONLogger(): Support logging to a Unix domain socket
This commit is contained in:
parent
d9730fc93b
commit
220000dc1a
4 changed files with 18 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "source-path.hh"
|
||||
#include "position.hh"
|
||||
#include "sync.hh"
|
||||
#include "unix-domain-socket.hh"
|
||||
|
||||
#include <atomic>
|
||||
#include <sstream>
|
||||
|
@ -296,7 +297,10 @@ Logger * makeJSONLogger(const std::filesystem::path & path, bool includeNixPrefi
|
|||
{ }
|
||||
};
|
||||
|
||||
AutoCloseFD fd{toDescriptor(open(path.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0644))};
|
||||
AutoCloseFD fd =
|
||||
std::filesystem::is_socket(path)
|
||||
? connect(path)
|
||||
: toDescriptor(open(path.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0644));
|
||||
if (!fd)
|
||||
throw SysError("opening log file '%1%'", 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,4 +80,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);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue