Skip to content

Commit 4aeec04

Browse files
committed
muvm-guest: pass config to split remote process
Signed-off-by: Val Packett <[email protected]>
1 parent adeadc7 commit 4aeec04

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

crates/muvm/src/bin/muvm.rs

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

468468
let krun_config_env = CString::new(format!("KRUN_CONFIG={}", config_file.path().display()))
469469
.context("Failed to process config_file var as it contains NUL character")?;
470+
#[allow(unused_assignments)] // wat?
471+
let mut muvm_config_env = None; // keep in this scope
470472
let mut env: Vec<*const c_char> = vec![krun_config_env.as_ptr()];
471473
if custom_init {
472474
env.push(c"KRUN_INIT_PID1=1".as_ptr());
475+
muvm_config_env = Some(
476+
CString::new(format!(
477+
"MUVM_REMOTE_CONFIG={}",
478+
muvm_config_file.path().display()
479+
))
480+
.context("Failed to process internal config path as it contains NUL character")?,
481+
);
482+
env.push(muvm_config_env.as_ref().unwrap().as_ptr());
473483
}
474484
env.push(std::ptr::null());
475485

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ use rustix::process::{getrlimit, setrlimit, Resource};
2525

2626
const KRUN_CONFIG: &str = "KRUN_CONFIG";
2727

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

@@ -38,9 +54,13 @@ fn main() -> Result<()> {
3854
},
3955
"muvm-remote" => {
4056
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()));
57+
let config_path =
58+
env::var("MUVM_REMOTE_CONFIG").context("expected MUVM_REMOTE_CONFIG to be set")?;
59+
let options = parse_config(config_path)?;
60+
return rt.block_on(server_main(
61+
options.command.command,
62+
options.command.command_args,
63+
));
4464
},
4565
_ => { /* continue with all-in-one mode */ },
4666
}
@@ -53,19 +73,7 @@ fn main() -> Result<()> {
5373
let config_path = env::args()
5474
.nth(1)
5575
.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)?;
76+
let options = parse_config(config_path)?;
6977

7078
{
7179
const ESYNC_RLIMIT_NOFILE: u64 = 524288;

0 commit comments

Comments
 (0)