Skip to content

Commit 8be45f2

Browse files
committed
muvm-guest: pass config to split remote process
Signed-off-by: Val Packett <[email protected]>
1 parent 89ff899 commit 8be45f2

2 files changed

Lines changed: 36 additions & 19 deletions

File tree

crates/muvm/src/bin/muvm.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,19 @@ fn main() -> Result<ExitCode> {
478478

479479
let krun_config_env = CString::new(format!("KRUN_CONFIG={}", config_file.path().display()))
480480
.context("Failed to process config_file var as it contains NUL character")?;
481+
#[allow(unused_assignments)] // wat?
482+
let mut muvm_config_env = None; // keep in this scope
481483
let mut env: Vec<*const c_char> = vec![krun_config_env.as_ptr()];
482484
if custom_init {
483485
env.push(c"KRUN_INIT_PID1=1".as_ptr());
486+
muvm_config_env = Some(
487+
CString::new(format!(
488+
"MUVM_REMOTE_CONFIG={}",
489+
muvm_config_file.path().display()
490+
))
491+
.context("Failed to process internal config path as it contains NUL character")?,
492+
);
493+
env.push(muvm_config_env.as_ref().unwrap().as_ptr());
484494
}
485495
env.push(std::ptr::null());
486496

crates/muvm/src/guest/bin/muvm-guest.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fs::File;
22
use std::io::Read;
33
use std::os::fd::AsFd;
44
use std::panic::catch_unwind;
5-
use std::path::PathBuf;
65
use std::process::{Command, ExitCode};
76
use std::{cmp, env, fs, thread};
87

@@ -25,22 +24,42 @@ use rustix::process::{getrlimit, setrlimit, Resource};
2524

2625
const KRUN_CONFIG: &str = "KRUN_CONFIG";
2726

27+
fn parse_config(config_path: String) -> Result<GuestConfiguration> {
28+
let mut config_file = File::open(&config_path)?;
29+
let mut config_buf = Vec::new();
30+
config_file.read_to_end(&mut config_buf)?;
31+
fs::remove_file(config_path).context("Unable to delete temporary muvm configuration file")?;
32+
if let Ok(krun_config_path) = env::var(KRUN_CONFIG) {
33+
fs::remove_file(krun_config_path)
34+
.context("Unable to delete temporary krun configuration file")?;
35+
// SAFETY: We are single-threaded at this point
36+
env::remove_var(KRUN_CONFIG);
37+
}
38+
// SAFETY: We are single-threaded at this point
39+
env::remove_var("KRUN_WORKDIR");
40+
Ok(serde_json::from_slice::<GuestConfiguration>(&config_buf)?)
41+
}
42+
2843
fn main() -> Result<ExitCode> {
2944
env_logger::init();
3045

3146
let binary_path = env::args().next().context("arg0")?;
3247
let bb = binary_path.split('/').next_back().context("arg0 split")?;
3348
match bb {
34-
"muvm-configure-network" => return configure_network(),
49+
"muvm-configure-network" => return configure_network().map(|()| ExitCode::SUCCESS),
3550
"muvm-pwbridge" => {
3651
bridge_loop_with_listenfd::<PipeWireProtocolHandler>(pipewire_sock_path);
37-
return Ok(());
52+
return Ok(ExitCode::SUCCESS);
3853
},
3954
"muvm-remote" => {
4055
let rt = tokio::runtime::Runtime::new().unwrap();
41-
let mut command_args = env::args().skip(1);
42-
let command = command_args.next().context("command name")?;
43-
return rt.block_on(server_main(PathBuf::from(command), command_args.collect()));
56+
let config_path =
57+
env::var("MUVM_REMOTE_CONFIG").context("expected MUVM_REMOTE_CONFIG to be set")?;
58+
let options = parse_config(config_path)?;
59+
return rt.block_on(server_main(
60+
options.command.command,
61+
options.command.command_args,
62+
));
4463
},
4564
_ => { /* continue with all-in-one mode */ },
4665
}
@@ -53,19 +72,7 @@ fn main() -> Result<ExitCode> {
5372
let config_path = env::args()
5473
.nth(1)
5574
.context("expected configuration file path")?;
56-
let mut config_file = File::open(&config_path)?;
57-
let mut config_buf = Vec::new();
58-
config_file.read_to_end(&mut config_buf)?;
59-
fs::remove_file(config_path).context("Unable to delete temporary muvm configuration file")?;
60-
if let Ok(krun_config_path) = env::var(KRUN_CONFIG) {
61-
fs::remove_file(krun_config_path)
62-
.context("Unable to delete temporary krun configuration file")?;
63-
// SAFETY: We are single-threaded at this point
64-
env::remove_var(KRUN_CONFIG);
65-
}
66-
// SAFETY: We are single-threaded at this point
67-
env::remove_var("KRUN_WORKDIR");
68-
let options = serde_json::from_slice::<GuestConfiguration>(&config_buf)?;
75+
let options = parse_config(config_path)?;
6976

7077
{
7178
const ESYNC_RLIMIT_NOFILE: u64 = 524288;

0 commit comments

Comments
 (0)