From 4251f94b32daed2abb0324439466876a97acdb77 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 3 Dec 2006 02:36:44 +0000 Subject: [PATCH] * Use a Unix domain socket instead of pipes. --- src/libstore/remote-store.cc | 30 +++++++++++++++++------------- src/libstore/remote-store.hh | 3 +-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index f724ac62f..f1d226fb8 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -17,10 +18,14 @@ namespace nix { RemoteStore::RemoteStore() { - toChild.create(); - fromChild.create(); + int sockets[2]; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1) + throw SysError("cannot create sockets"); + fdSelf = sockets[0]; + AutoCloseFD fdChild = sockets[1]; + /* Start the worker. */ string worker = "nix-worker"; @@ -33,15 +38,16 @@ RemoteStore::RemoteStore() case 0: try { /* child */ - - fromChild.readSide.close(); - if (dup2(fromChild.writeSide, STDOUT_FILENO) == -1) + + if (dup2(fdChild, STDOUT_FILENO) == -1) throw SysError("dupping write side"); - toChild.writeSide.close(); - if (dup2(toChild.readSide, STDIN_FILENO) == -1) + if (dup2(fdChild, STDIN_FILENO) == -1) throw SysError("dupping read side"); + close(fdSelf); + close(fdChild); + int fdDebug = open("/tmp/worker-log", O_WRONLY | O_CREAT | O_TRUNC, 0644); assert(fdDebug != -1); if (dup2(fdDebug, STDERR_FILENO) == -1) @@ -59,11 +65,10 @@ RemoteStore::RemoteStore() quickExit(1); } - fromChild.writeSide.close(); - toChild.readSide.close(); + fdChild.close(); - from.fd = fromChild.readSide; - to.fd = toChild.writeSide; + from.fd = fdSelf; + to.fd = fdSelf; /* Send the magic greeting, check for the reply. */ @@ -81,8 +86,7 @@ RemoteStore::RemoteStore() RemoteStore::~RemoteStore() { try { - fromChild.readSide.close(); - toChild.writeSide.close(); + fdSelf.close(); child.wait(true); } catch (Error & e) { printMsg(lvlError, format("error (ignored): %1%") % e.msg()); diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 05d2a21ec..ed44f6d54 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -52,8 +52,7 @@ public: void syncWithGC(); private: - Pipe toChild; - Pipe fromChild; + AutoCloseFD fdSelf; FdSink to; FdSource from; Pid child;