Skip to content

Commit

Permalink
env: Force a separate Firefox profile
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
asahilina authored and slp committed Dec 9, 2024
1 parent ae8b243 commit f464c62
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/muvm/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ pub fn prepare_env_vars(env: Vec<(String, Option<String>)>) -> Result<HashMap<St
env_map.insert("GTK_IM_MODULE".to_owned(), "xim".to_owned());
env_map.insert("QT_IM_MODULE".to_owned(), "xim".to_owned());

// Force a separate Firefox profile, since Firefox in muvm cannot see
// the lock from outside the VM and will concurrently launch on the same
// profile, corrupting it. This makes Firefox safely work in the VM
// (for browser launches).
if let Ok(home) = env::var("HOME") {
let mut path = PathBuf::new();
path.push(home);
path.push(".mozilla");
path.push("firefox");
if path.exists() {
path.push("muvm-profile");
if !path.exists() {
std::fs::create_dir(&path)?;
}
env_map.insert(
"XRE_PROFILE_PATH".to_owned(),
path.to_str().unwrap().to_owned(),
);
}
}

for (key, value) in env {
let value = value.map_or_else(
|| env::var(&key).with_context(|| format!("Failed to get `{key}` env var")),
Expand Down

0 comments on commit f464c62

Please sign in to comment.