aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-12-22 12:28:50 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-22 12:28:50 +0100
commit5373f4be3b1427ed73303448a1fa801726f4dfa0 (patch)
tree5dc641a29f69a4075319dd86320e59eedb477935 /src/nix
parent724b7f4fb660212a97ba6482208c299158720c5b (diff)
chrootHelper: Handle symlinks in the root directory
This is necessary on Ubuntu where /bin and /lib* are symlinks.
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/run.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/nix/run.cc b/src/nix/run.cc
index 92a52c6cd..ec61fc79a 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -258,14 +258,16 @@ void chrootHelper(int argc, char * * argv)
for (auto entry : readDirectory("/")) {
auto src = "/" + entry.name;
- auto st = lstat(src);
- if (!S_ISDIR(st.st_mode)) continue;
Path dst = tmpDir + "/" + entry.name;
if (pathExists(dst)) continue;
- if (mkdir(dst.c_str(), 0700) == -1)
- throw SysError("creating directory '%s'", dst);
- if (mount(src.c_str(), dst.c_str(), "", MS_BIND | MS_REC, 0) == -1)
- throw SysError("mounting '%s' on '%s'", src, dst);
+ auto st = lstat(src);
+ if (S_ISDIR(st.st_mode)) {
+ if (mkdir(dst.c_str(), 0700) == -1)
+ throw SysError("creating directory '%s'", dst);
+ if (mount(src.c_str(), dst.c_str(), "", MS_BIND | MS_REC, 0) == -1)
+ throw SysError("mounting '%s' on '%s'", src, dst);
+ } else if (S_ISLNK(st.st_mode))
+ createSymlink(readLink(src), dst);
}
char * cwd = getcwd(0, 0);