summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorAllen Webb <allenwebb@google.com>2019-02-22 08:47:03 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-02-27 01:13:47 -0800
commitdeb0891b9c0cb0157d545e0479906653c9ccbb1e (patch)
tree9808d44b366fee67602bdde9b9a5f26a20ca06a6 /src/linux.rs
parent18ce5713e6cb99c40aafec52b67c28ba12a44f31 (diff)
downloadcrosvm-deb0891b9c0cb0157d545e0479906653c9ccbb1e.tar
crosvm-deb0891b9c0cb0157d545e0479906653c9ccbb1e.tar.gz
crosvm-deb0891b9c0cb0157d545e0479906653c9ccbb1e.tar.bz2
crosvm-deb0891b9c0cb0157d545e0479906653c9ccbb1e.tar.lz
crosvm-deb0891b9c0cb0157d545e0479906653c9ccbb1e.tar.xz
crosvm-deb0891b9c0cb0157d545e0479906653c9ccbb1e.tar.zst
crosvm-deb0891b9c0cb0157d545e0479906653c9ccbb1e.zip
linux: Add DEFAULT_PIVOT_ROOT var which can be changed at build time.
This allows the default pivot root used by crosvm to be defined at
build time. If it is not set, /var/empty is used.

BUG=chromium:934513,chromium:933582
TEST=PreCQ passes

Change-Id: I2b461170e6b75324740d4ff709fd599085cefe18
Reviewed-on: https://chromium-review.googlesource.com/1483330
Commit-Ready: Allen Webb <allenwebb@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 2d6673d..20ef297 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -67,7 +67,7 @@ pub enum Error {
     InvalidFdPath,
     InvalidWaylandPath,
     NetDeviceNew(devices::virtio::NetError),
-    NoVarEmpty,
+    PivotRootDoesntExist(&'static str),
     OpenAndroidFstab(PathBuf, io::Error),
     OpenInitrd(PathBuf, io::Error),
     OpenKernel(PathBuf, io::Error),
@@ -126,7 +126,7 @@ impl fmt::Display for Error {
                 write!(f, "wayland socket path has no parent or file name")
             }
             Error::NetDeviceNew(e) => write!(f, "failed to set up virtio networking: {}", e),
-            Error::NoVarEmpty => write!(f, "/var/empty doesn't exist, can't jail devices."),
+            Error::PivotRootDoesntExist(p) => write!(f, "{} doesn't exist, can't jail devices.", p),
             Error::OpenInitrd(p, e) => write!(f, "failed to open initrd {}: {}", p.display(), e),
             Error::OpenKernel(p, e) => {
                 write!(f, "failed to open kernel image {}: {}", p.display(), e)
@@ -227,14 +227,14 @@ fn create_virtio_devs(
     balloon_device_socket: UnixDatagram,
     disk_device_sockets: &mut Vec<UnixDatagram>,
 ) -> std::result::Result<Vec<(Box<PciDevice + 'static>, Option<Minijail>)>, Box<error::Error>> {
-    static DEFAULT_PIVOT_ROOT: &str = "/var/empty";
+    let default_pivot_root: &str = option_env!("DEFAULT_PIVOT_ROOT").unwrap_or("/var/empty");
 
     let mut devs = Vec::new();
 
     // An empty directory for jailed device's pivot root.
-    let empty_root_path = Path::new(DEFAULT_PIVOT_ROOT);
+    let empty_root_path = Path::new(default_pivot_root);
     if cfg.multiprocess && !empty_root_path.exists() {
-        return Err(Box::new(Error::NoVarEmpty));
+        return Err(Box::new(Error::PivotRootDoesntExist(default_pivot_root)));
     }
 
     for disk in &cfg.disks {