Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uh_init: Handle safety around set_var #514

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions openhcl/underhill_core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,12 +1165,6 @@ async fn new_underhill_vm(
control_send,
} = params;

if let Ok(kernel_boot_time) = std::env::var("KERNEL_BOOT_TIME") {
if let Ok(kernel_boot_time_ns) = kernel_boot_time.parse::<u64>() {
tracing::info!(kernel_boot_time_ns, "kernel boot time");
}
}

// Read the initial configuration from the IGVM parameters.
let (runtime_params, measured_vtl2_info) =
crate::loader::vtl2_config::read_vtl2_params().context("failed to read load parameters")?;
Expand Down
19 changes: 13 additions & 6 deletions openhcl/underhill_init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ fn setup(

use_host_entropy().context("use host entropy")?;

for setup in &options.setup_script {
Ok(())
}

fn run_setup_scripts(scripts: &[String]) -> anyhow::Result<Vec<(String, String)>> {
let mut new_env = Vec::new();
for setup in scripts {
log::info!("Running provided setup script {}", setup);

let result = Command::new("/bin/sh")
Expand All @@ -226,17 +231,18 @@ fn setup(
.and_then(|line| line.split_once('='))
{
log::info!("setting env var {}={}", key, value);
std::env::set_var(key, value);
new_env.push((key.into(), value.into()));
}
}
}
Ok(())
Ok(new_env)
}

fn run(options: &Options) -> anyhow::Result<()> {
fn run(options: &Options, env: impl IntoIterator<Item = (String, String)>) -> anyhow::Result<()> {
let mut command = Command::new(UNDERHILL_PATH);
command.arg("--pid").arg("/run/underhill.pid");
command.args(&options.underhill_args);
command.envs(env);

// Update the file descriptor limit for the main process, since large VMs
// require lots of fds. There is no downside to a larger value except that
Expand Down Expand Up @@ -423,10 +429,10 @@ fn timestamp() -> u64 {

fn do_main() -> anyhow::Result<()> {
let boot_time = timestamp();
std::env::set_var("KERNEL_BOOT_TIME", boot_time.to_string());

init_logging();

log::info!("kernel boot time {}", boot_time);
log::info!(
"Initial process: crate_name={}, crate_revision={}, crate_branch={}",
env!("CARGO_PKG_NAME"),
Expand Down Expand Up @@ -550,6 +556,7 @@ fn do_main() -> anyhow::Result<()> {
];

setup(&stat_files, &options, writes, &filesystems)?;
let new_env = run_setup_scripts(&options.setup_script)?;

if matches!(
std::env::var("OPENHCL_NVME_VFIO").as_deref(),
Expand All @@ -574,7 +581,7 @@ fn do_main() -> anyhow::Result<()> {
}
});

run(&options)
run(&options, new_env)
}

pub fn main() -> ! {
Expand Down
Loading