From 42f5a2fc297f841d982f07062c653b27557a3cd5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 27 Jun 2012 09:52:27 -0400 Subject: [PATCH] Mount an empty /dev/shm tmpfs in the chroot This ensures that whatever the builder writes in /dev/shm is automatically cleaned up. --- src/libstore/build.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index e7a8ee434..246e0d9da 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1868,6 +1868,12 @@ void DerivationGoal::initChild() private PID namespace. */ 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