Skip to content

Commit

Permalink
guest: allow writing to etc
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Rosenzweig <[email protected]>
  • Loading branch information
alyssarosenzweig committed Oct 7, 2024
1 parent fa8821c commit eabdad1
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions crates/muvm/src/guest/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,22 @@ fn mount_fex_rootfs() -> Result<()> {
Ok(())
}

pub fn place_etc(file: &str) -> Result<()> {
pub fn place_etc(file: &str, contents: Option<&str>) -> Result<()> {
let tmp = "/tmp/".to_string() + file;
let etc = "/etc/".to_string() + file;

let _ = File::options()
.write(true)
.create(true)
.truncate(true)
.open(&tmp)
.context("Failed to create temp backing of an etc file")?;
{
let mut file = File::options()
.write(true)
.create(true)
.truncate(true)
.open(&tmp)
.context("Failed to create temp backing of an etc file")?;

if let Some(content) = contents {
file.write_all(content.as_bytes()).context("Failed to write tmp backing of etc")?;
}
}

let fd = open_tree(
CWD,
Expand All @@ -127,7 +133,7 @@ pub fn mount_filesystems() -> Result<()> {
println!("Failed to mount FEX rootfs, carrying on without.")
}

place_etc("resolv.conf")?;
place_etc("resolv.conf", None)?;

mount2(
Some("binfmt_misc"),
Expand Down

0 comments on commit eabdad1

Please sign in to comment.