about summary refs log tree commit diff
path: root/src/nix/run.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-11-20T16·58+0100
committerEelco Dolstra <edolstra@gmail.com>2017-11-20T16·58+0100
commita3aa850f0f71644ac4559f958e180c3e543c74e9 (patch)
treebd6883f5cb50b995aec6d6967944d9f7288f2d43 /src/nix/run.cc
parent193330d321d3e394d1ce01c7e1dbea28ace68323 (diff)
nix run: Ignore non-directories while setting up the chroot
Fixes #1686.
Diffstat (limited to 'src/nix/run.cc')
-rw-r--r--src/nix/run.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/nix/run.cc b/src/nix/run.cc
index 6657a86314bf..11acbc3db673 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -195,12 +195,15 @@ void chrootHelper(int argc, char * * argv)
             throw SysError("mounting '%s' on '%s'", realStoreDir, storeDir);
 
         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(format("creating directory '%s'") % dst);
-            if (mount(("/" + entry.name).c_str(), dst.c_str(), "", MS_BIND | MS_REC, 0) == -1)
-                throw SysError(format("mounting '%s' on '%s'") %  ("/" + entry.name) % dst);
+                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);
         }
 
         char * cwd = getcwd(0, 0);