about summary refs log tree commit diff
path: root/src/nix-worker
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-11-30T19·19+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-11-30T19·19+0000
commit40b3f64b55f98e03b3173541b8d94cd924099223 (patch)
tree78a14654425eab2729e3c8077860573766a794c0 /src/nix-worker
parent9adc074dc3e135356c2390038bf72264c29c1e03 (diff)
* Skeleton of the privileged worker program.
* Some refactoring: put the NAR archive integer/string serialisation
  code in a separate file so it can be reused by the worker protocol
  implementation.

Diffstat (limited to 'src/nix-worker')
-rw-r--r--src/nix-worker/Makefile.am9
-rw-r--r--src/nix-worker/main.cc63
2 files changed, 72 insertions, 0 deletions
diff --git a/src/nix-worker/Makefile.am b/src/nix-worker/Makefile.am
new file mode 100644
index 000000000000..6f10efff5d57
--- /dev/null
+++ b/src/nix-worker/Makefile.am
@@ -0,0 +1,9 @@
+libexec_PROGRAMS = nix-worker
+
+nix_worker_SOURCES = main.cc
+nix_worker_LDADD = ../libmain/libmain.la ../libstore/libstore.la ../libutil/libutil.la \
+ ../boost/format/libformat.la ${bdb_lib} ${aterm_lib}
+
+AM_CXXFLAGS = \
+ -I$(srcdir)/.. ${bdb_include} $(aterm_include) -I$(srcdir)/../libutil \
+ -I$(srcdir)/../libstore -I$(srcdir)/../libmain
diff --git a/src/nix-worker/main.cc b/src/nix-worker/main.cc
new file mode 100644
index 000000000000..4fe92a85adec
--- /dev/null
+++ b/src/nix-worker/main.cc
@@ -0,0 +1,63 @@
+#include "shared.hh"
+#include "local-store.hh"
+#include "util.hh"
+
+using namespace nix;
+
+
+/* !!! Mostly cut&pasted from util/archive.hh */
+/* Use buffered reads. */
+static unsigned int readInt(int fd)
+{
+    unsigned char buf[8];
+    readFull(fd, buf, sizeof(buf));
+    if (buf[4] || buf[5] || buf[6] || buf[7])
+        throw Error("implementation cannot deal with > 32-bit integers");
+    return
+        buf[0] |
+        (buf[1] << 8) |
+        (buf[2] << 16) |
+        (buf[3] << 24);
+}
+
+
+void processConnection(int fdFrom, int fdTo)
+{
+    store = openStore();
+
+    unsigned int magic = readInt(fdFrom);
+    if (magic != 0x6e697864) throw Error("protocol mismatch");
+
+    
+    
+}
+
+
+void run(Strings args)
+{
+    bool slave = false;
+    bool daemon = false;
+    
+    for (Strings::iterator i = args.begin(); i != args.end(); ) {
+        string arg = *i++;
+        if (arg == "--slave") slave = true;
+    }
+
+    if (slave)
+        processConnection(STDIN_FILENO, STDOUT_FILENO);
+
+    else if (daemon)
+        throw Error("daemon mode not implemented");
+
+    else
+        throw Error("must be run in either --slave or --daemon mode");
+        
+}
+
+
+void printHelp()
+{
+}
+
+
+string programId = "nix-store";