Skip to content

Commit f464c62

Browse files
hoshinolinaslp
authored andcommitted
env: Force a separate Firefox profile
Otherwise Firefox launched in the guest will concurrently access the host profile, corrupting it. We can make it not do that by implementing locks, which would fix the corruption but would still break the browser in the guest. So let's explicitly set a muvm-private Firefox profile. Signed-off-by: Asahi Lina <[email protected]>
1 parent ae8b243 commit f464c62

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

crates/muvm/src/env.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@ pub fn prepare_env_vars(env: Vec<(String, Option<String>)>) -> Result<HashMap<St
9090
env_map.insert("GTK_IM_MODULE".to_owned(), "xim".to_owned());
9191
env_map.insert("QT_IM_MODULE".to_owned(), "xim".to_owned());
9292

93+
// Force a separate Firefox profile, since Firefox in muvm cannot see
94+
// the lock from outside the VM and will concurrently launch on the same
95+
// profile, corrupting it. This makes Firefox safely work in the VM
96+
// (for browser launches).
97+
if let Ok(home) = env::var("HOME") {
98+
let mut path = PathBuf::new();
99+
path.push(home);
100+
path.push(".mozilla");
101+
path.push("firefox");
102+
if path.exists() {
103+
path.push("muvm-profile");
104+
if !path.exists() {
105+
std::fs::create_dir(&path)?;
106+
}
107+
env_map.insert(
108+
"XRE_PROFILE_PATH".to_owned(),
109+
path.to_str().unwrap().to_owned(),
110+
);
111+
}
112+
}
113+
93114
for (key, value) in env {
94115
let value = value.map_or_else(
95116
|| env::var(&key).with_context(|| format!("Failed to get `{key}` env var")),

0 commit comments

Comments
 (0)