about summary refs log tree commit diff
path: root/src/nix-worker/nix-worker.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-04-09T05·57+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-04-09T05·57+0000
commit72034ab35d5ba8c2b229fe36375a15b2a8b5b68c (patch)
tree0d0d0e4441b697a1a05e33a2fb7126fbf79e1f31 /src/nix-worker/nix-worker.cc
parentf8985d195e600387fd03137872bb27cec65b2492 (diff)
* sockaddr_un doesn't allow path names of more than 108 characters.
  This isn't usually a problem, except that it causes tests to fail
  when performed in a directory with a very long path name.  So chdir
  to the socket directory and use a relative path name.

Diffstat (limited to 'src/nix-worker/nix-worker.cc')
-rw-r--r--src/nix-worker/nix-worker.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc
index 4aab03fcd6..d9b75270f8 100644
--- a/src/nix-worker/nix-worker.cc
+++ b/src/nix-worker/nix-worker.cc
@@ -542,11 +542,17 @@ static void daemonLoop()
 
     createDirs(dirOf(socketPath));
 
+    /* Urgh, sockaddr_un allows path names of only 108 characters.  So
+       chdir to the socket directory so that we can pass a relative
+       path name. */
+    chdir(dirOf(socketPath).c_str());
+    Path socketPathRel = "./" + baseNameOf(socketPath);
+    
     struct sockaddr_un addr;
     addr.sun_family = AF_UNIX;
-    if (socketPath.size() >= sizeof(addr.sun_path))
-        throw Error(format("socket path `%1%' is too long") % socketPath);
-    strcpy(addr.sun_path, socketPath.c_str());
+    if (socketPathRel.size() >= sizeof(addr.sun_path))
+        throw Error(format("socket path `%1%' is too long") % socketPathRel);
+    strcpy(addr.sun_path, socketPathRel.c_str());
 
     unlink(socketPath.c_str());
 
@@ -559,6 +565,8 @@ static void daemonLoop()
     if (res == -1)
         throw SysError(format("cannot bind to socket `%1%'") % socketPath);
 
+    chdir("/"); /* back to the root */
+
     if (listen(fdSocket, 5) == -1)
         throw SysError(format("cannot listen on socket `%1%'") % socketPath);