diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-04-09T05·57+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-04-09T05·57+0000 |
commit | 72034ab35d5ba8c2b229fe36375a15b2a8b5b68c (patch) | |
tree | 0d0d0e4441b697a1a05e33a2fb7126fbf79e1f31 /src/libstore | |
parent | f8985d195e600387fd03137872bb27cec65b2492 (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/libstore')
-rw-r--r-- | src/libstore/remote-store.cc | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 88a2fca8aedd..14412b8c8b60 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -137,14 +137,26 @@ void RemoteStore::connectToDaemon() string socketPath = nixStateDir + DEFAULT_SOCKET_PATH; + /* 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. !!! this is probably a bad idea in multi-threaded + applications... */ + AutoCloseFD fdPrevDir = open(".", O_RDONLY); + if (fdPrevDir == -1) throw SysError("couldn't open current directory"); + 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()); if (connect(fdSocket, (struct sockaddr *) &addr, sizeof(addr)) == -1) throw SysError(format("cannot connect to daemon at `%1%'") % socketPath); + + if (fchdir(fdPrevDir) == -1) + throw SysError("couldn't change back to previous directory"); } |