about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-12-04T13·28+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-12-04T13·28+0000
commitf5f0cf423fda5e030d9be6fd6500a1b06d3a60bc (patch)
tree1f61202f7b956cb704cfbeb51c39ba06cb9cb350 /src/libstore
parent052b6fb1495cd606d35cd3eb1806f9fe0019e6ca (diff)
* Refactoring.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/remote-store.cc42
-rw-r--r--src/libstore/remote-store.hh2
-rw-r--r--src/libstore/store-api.cc6
3 files changed, 33 insertions, 17 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 11e6c42fab82..df1c1616f879 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -19,6 +19,35 @@ namespace nix {
 
 RemoteStore::RemoteStore()
 {
+    string remoteMode = getEnv("NIX_REMOTE");
+
+    if (remoteMode == "slave")
+        /* Fork off a setuid worker to do the privileged work. */
+        forkSlave();
+    else if (remoteMode == "daemon")
+        /* Connect to a daemon that does the privileged work for
+           us. */
+        ;
+    else
+         throw Error(format("invalid setting for NIX_REMOTE, `%1%'")
+             % remoteMode);
+            
+    
+    /* Send the magic greeting, check for the reply. */
+    try {
+        processStderr();
+        writeInt(WORKER_MAGIC_1, to);
+        unsigned int magic = readInt(from);
+        if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
+    } catch (Error & e) {
+        throw Error(format("cannot start worker (%1%)")
+            % e.msg());
+    }
+}
+
+
+void RemoteStore::forkSlave()
+{
     int sockets[2];
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == -1)
         throw SysError("cannot create sockets");
@@ -26,7 +55,6 @@ RemoteStore::RemoteStore()
     fdSelf = sockets[0];
     AutoCloseFD fdChild = sockets[1];
 
-    
     /* Start the worker. */
     Path worker = getEnv("NIX_WORKER");
     if (worker == "")
@@ -78,18 +106,6 @@ RemoteStore::RemoteStore()
 
     from.fd = fdSelf;
     to.fd = fdSelf;
-
-    
-    /* Send the magic greeting, check for the reply. */
-    try {
-        processStderr();
-        writeInt(WORKER_MAGIC_1, to);
-        unsigned int magic = readInt(from);
-        if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
-    } catch (Error & e) {
-        throw Error(format("cannot start worker process `%1%' (%2%)")
-            % worker % e.msg());
-    }
 }
 
 
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index ed44f6d54c66..a8e2f788e989 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -58,6 +58,8 @@ private:
     Pid child;
 
     void processStderr();
+
+    void forkSlave();
 };
 
 
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index fb86fc6abbb7..677c3ca3e909 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -137,12 +137,10 @@ boost::shared_ptr<StoreAPI> store;
 
 boost::shared_ptr<StoreAPI> openStore(bool reserveSpace)
 {
-    string mode = getEnv("NIX_REMOTE");
-    if (mode == "")
+    if (getEnv("NIX_REMOTE") == "")
         return boost::shared_ptr<StoreAPI>(new LocalStore(reserveSpace));
-    else if (mode == "slave")
+    else
         return boost::shared_ptr<StoreAPI>(new RemoteStore());
-    else throw Error(format("invalid setting for NIX_REMOTE, `%1%'") % mode);
 }