diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-03T02·36+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-12-03T02·36+0000 |
commit | 4251f94b32daed2abb0324439466876a97acdb77 (patch) | |
tree | 7f0952c5cc3027f6030047666e10f1dc2381dce7 | |
parent | 8c76df93e6fe021df6a6aa2b2c710202db326a34 (diff) |
* Use a Unix domain socket instead of pipes.
-rw-r--r-- | src/libstore/remote-store.cc | 30 | ||||
-rw-r--r-- | 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 f724ac62f715..f1d226fb8b02 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -6,6 +6,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/socket.h> #include <fcntl.h> #include <iostream> @@ -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 05d2a21ecb23..ed44f6d54c66 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; |