Skip to content

Commit

Permalink
boot-image: Pass additional args to the hypervisor
Browse files Browse the repository at this point in the history
  • Loading branch information
YtvwlD committed Jun 14, 2024
1 parent 1a371d8 commit b534ae0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ fn build_and_boot(
false,
true, // the firmware seems to boot only on KVM
false,
&["-display", "none"],
)?;
let mut qemu_process = qemu_command
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.arg("-display").arg("none")
.spawn()?;
sleep(Duration::from_secs(5)); // TODO: kernels should probably terminate the VM
qemu_process.kill()?; // there's no terminate here
Expand Down
12 changes: 9 additions & 3 deletions towbootctl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ pub fn create_image(
}

/// Boot a built image, returning the running process.
pub fn boot_image(
pub fn boot_image<S: AsRef<str> + std::convert::AsRef<std::ffi::OsStr>>(
firmware: Option<&Path>, image: &Path, is_x86_64: bool, use_bochs: bool,
use_kvm: bool, use_gdb: bool,
use_kvm: bool, use_gdb: bool, args: &[S],
) -> Result<(Command, Vec<TempPath>)> {
info!("getting firmware");
let firmware_path = if let Some(path) = firmware {
Expand All @@ -135,6 +135,7 @@ pub fn boot_image(
let config = bochsrc(&firmware_path, image, use_gdb)?.into_temp_path();
let mut bochs = Command::new("bochs");
bochs.arg("-qf").arg(config.as_os_str());
bochs.args(args);
(bochs, vec![config])
} else {
info!("spawning QEMU");
Expand All @@ -154,6 +155,7 @@ pub fn boot_image(
info!("The machine starts paused, waiting for GDB to attach to localhost:1234.");
qemu.arg("-s").arg("-S");
}
qemu.args(args);
(qemu, vec![])
})
}
Expand Down Expand Up @@ -186,14 +188,18 @@ pub struct BootImageCommand {
/// use the specified firmware instead of OVMF
#[argh(option)]
firmware: Option<PathBuf>,

/// additional arguments to pass to the hypervisor
#[argh(positional, greedy)]
args: Vec<String>,
}

#[cfg(feature = "args")]
impl BootImageCommand {
pub fn r#do(&self) -> Result<()> {
let (mut process, _temp_files) = boot_image(
self.firmware.as_deref(), &self.image, self.x86_64, self.bochs,
self.kvm, self.gdb,
self.kvm, self.gdb, &self.args,
)?;
process.status()?.exit_ok()?;
Ok(())
Expand Down

0 comments on commit b534ae0

Please sign in to comment.