MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / write_guest_env_file

Function write_guest_env_file

crates/openshell-driver-vm/src/runtime.rs:258–271  ·  view source on GitHub ↗

Write environment variables into the overlay disk so the guest init script can source them after the overlay root is mounted. QEMU does not provide a `krun_set_exec` equivalent, so the launcher injects this small per-sandbox file into the overlay upperdir before boot.

(overlay_disk: &Path, env_vars: &[String])

Source from the content-addressed store, hash-verified

256/// `krun_set_exec` equivalent, so the launcher injects this small per-sandbox
257/// file into the overlay upperdir before boot.
258fn write_guest_env_file(overlay_disk: &Path, env_vars: &[String]) -> Result<(), String> {
259 let mut content = String::new();
260 for var in env_vars {
261 if let Some((key, value)) = var.split_once('=') {
262 use std::fmt::Write as _;
263 let _ = writeln!(content, "export {key}=\"{}\"", shell_escape(value));
264 }
265 }
266 rootfs::write_rootfs_image_file(
267 overlay_disk,
268 "/upper/srv/openshell-env.sh",
269 content.as_bytes(),
270 )
271}
272
273fn qemu_guest_env_vars(config: &VmLaunchConfig, dns_server: Option<String>) -> Vec<String> {
274 let mut env_vars = config.env.clone();

Callers 1

run_qemu_vmFunction · 0.85

Calls 1

write_rootfs_image_fileFunction · 0.85

Tested by

no test coverage detected