* Use a PathSet for the chroot directories so that we don't

accidentally bind-mount a directory twice.
This commit is contained in:
Eelco Dolstra 2008-12-12 11:49:42 +00:00
parent d86bd22d24
commit 6776a52bb3

View File

@ -1665,7 +1665,7 @@ void DerivationGoal::startBuilder()
work properly. Purity checking for fixed-output derivations work properly. Purity checking for fixed-output derivations
is somewhat pointless anyway. */ is somewhat pointless anyway. */
useChroot = queryBoolSetting("build-use-chroot", false); useChroot = queryBoolSetting("build-use-chroot", false);
Paths dirsInChroot; PathSet dirsInChroot;
if (fixedOutput) useChroot = false; if (fixedOutput) useChroot = false;
@ -1706,10 +1706,11 @@ void DerivationGoal::startBuilder()
defaultDirs.push_back("/dev"); defaultDirs.push_back("/dev");
defaultDirs.push_back("/dev/pts"); defaultDirs.push_back("/dev/pts");
defaultDirs.push_back("/proc"); defaultDirs.push_back("/proc");
dirsInChroot = querySetting("build-chroot-dirs", defaultDirs);
dirsInChroot.push_front(tmpDir); Paths dirsInChroot_ = querySetting("build-chroot-dirs", defaultDirs);
dirsInChroot.insert(dirsInChroot_.begin(), dirsInChroot_.end());
dirsInChroot.insert(tmpDir);
/* Make the closure of the inputs available in the chroot, /* Make the closure of the inputs available in the chroot,
rather than the whole Nix store. This prevents any access rather than the whole Nix store. This prevents any access
@ -1726,7 +1727,7 @@ void DerivationGoal::startBuilder()
if (lstat(i->c_str(), &st)) if (lstat(i->c_str(), &st))
throw SysError(format("getting attributes of path `%1%'") % *i); throw SysError(format("getting attributes of path `%1%'") % *i);
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
dirsInChroot.push_back(*i); dirsInChroot.insert(*i);
else { else {
Path p = chrootRootDir + *i; Path p = chrootRootDir + *i;
if (link(i->c_str(), p.c_str()) == -1) if (link(i->c_str(), p.c_str()) == -1)
@ -1776,7 +1777,7 @@ void DerivationGoal::startBuilder()
/* Bind-mount all the directories from the "host" /* Bind-mount all the directories from the "host"
filesystem that we want in the chroot filesystem that we want in the chroot
environment. */ environment. */
foreach (Paths::iterator, i, dirsInChroot) { foreach (PathSet::iterator, i, dirsInChroot) {
Path source = *i; Path source = *i;
Path target = chrootRootDir + source; Path target = chrootRootDir + source;
debug(format("bind mounting `%1%' to `%2%'") % source % target); debug(format("bind mounting `%1%' to `%2%'") % source % target);