Skip to content

Commit d0611e4

Browse files
alyssarosenzweigslp
authored andcommitted
guest: allow writing to etc
Signed-off-by: Alyssa Rosenzweig <[email protected]>
1 parent 96bed9c commit d0611e4

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

crates/muvm/src/guest/mount.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,23 @@ fn mount_fex_rootfs() -> Result<()> {
9292
Ok(())
9393
}
9494

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

99-
let _ = File::options()
100-
.write(true)
101-
.create(true)
102-
.truncate(true)
103-
.open(&tmp)
104-
.context("Failed to create temp backing of an etc file")?;
99+
{
100+
let mut file = File::options()
101+
.write(true)
102+
.create(true)
103+
.truncate(true)
104+
.open(&tmp)
105+
.context("Failed to create temp backing of an etc file")?;
106+
107+
if let Some(content) = contents {
108+
file.write_all(content.as_bytes())
109+
.context("Failed to write tmp backing of etc")?;
110+
}
111+
}
105112

106113
let fd = open_tree(
107114
CWD,
@@ -127,7 +134,7 @@ pub fn mount_filesystems() -> Result<()> {
127134
println!("Failed to mount FEX rootfs, carrying on without.")
128135
}
129136

130-
place_etc("resolv.conf")?;
137+
place_etc("resolv.conf", None)?;
131138

132139
mount2(
133140
Some("binfmt_misc"),

0 commit comments

Comments
 (0)