From 359fda36b6dcabea79a76b56e10d4d67702f545f Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Thu, 23 Jan 2014 20:11:57 +0100 Subject: [PATCH] Create tmpfs on /dev/shm after chrooting. src/libstore/build.cc: Create tmpfs on /dev/shm after chrooting. If /dev/shm is a link, create required directory for mounting. --- src/libstore/build.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 4329d9a..b01bf92 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -2054,12 +2054,6 @@ void DerivationGoal::initChild() if (mount("none", (chrootRootDir + "/proc").c_str(), "proc", 0, 0) == -1) throw SysError("mounting /proc"); - /* Mount a new tmpfs on /dev/shm to ensure that whatever - the builder puts in /dev/shm is cleaned up automatically. */ - if (pathExists("/dev/shm")) - if (mount("none", (chrootRootDir + "/dev/shm").c_str(), "tmpfs", 0, 0) == -1) - throw SysError("mounting /dev/shm"); - /* Do the chroot(). Below we do a chdir() to the temporary build directory to make sure the current directory is in the chroot. (Actually the order @@ -2067,6 +2061,17 @@ void DerivationGoal::initChild() tmpRootDit/tmpDir are the same directories.) */ if (chroot(chrootRootDir.c_str()) == -1) throw SysError(format("cannot change root directory to `%1%'") % chrootRootDir); + + /* Mount a new tmpfs on /dev/shm to ensure that whatever + the builder puts in /dev/shm is cleaned up automatically. */ + if (pathExists ("/dev/shm")) + { + Path target = "/dev/shm"; + if (isLink(target) && !pathExists(target = readLink(target))) + createDirs(target); + if (mount("none", "/dev/shm", "tmpfs", 0, 0) == -1) + throw SysError("mounting /dev/shm"); + } } #endif -- 1.7.10.4