Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 24 additions & 3 deletions crates/minvmd/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ pub const DEFAULT_DETACH_TIMEOUT_SECS: u64 = 8;
///
/// - `detach`: if true, spawn the supervisor in the background and poll until
/// the VM is serving (up to `timeout_secs`).
/// - `timeout_secs`: only used when `detach` is true; default 8 s.
pub fn run(detach: bool, timeout_secs: u64) -> Result<()> {
/// - `timeout_secs`: only meaningful under `--detach`; `None` when the flag was
/// omitted. Rejected without `--detach` rather than silently ignored;
/// defaults to [`DEFAULT_DETACH_TIMEOUT_SECS`] when detaching.
pub fn run(detach: bool, timeout_secs: Option<u64>) -> Result<()> {
// `--timeout` only bounds the detach poll loop; foreground runs supervise
// the VMM child for its whole life and never consult it. Accepting it in
// foreground mode would silently ignore it, so reject the combination.
if !detach && timeout_secs.is_some() {
bail!("`--timeout` only applies with `--detach`");
}
let timeout_secs = timeout_secs.unwrap_or(DEFAULT_DETACH_TIMEOUT_SECS);

#[cfg(minvmd_libkrun)]
return run_supervisor(detach, timeout_secs);

Expand Down Expand Up @@ -491,10 +501,21 @@ mod tests {
#[cfg(not(minvmd_libkrun))]
#[test]
fn run_bails_without_libkrun() {
let err = run(false, DEFAULT_DETACH_TIMEOUT_SECS).unwrap_err();
let err = run(false, None).unwrap_err();
assert!(
err.to_string().contains("requires libkrun"),
"expected libkrun-required message, got: {err}"
);
}

#[cfg(not(minvmd_libkrun))]
#[test]
fn run_rejects_timeout_without_detach() {
let err = run(false, Some(5)).unwrap_err();
assert!(
err.to_string()
.contains("`--timeout` only applies with `--detach`"),
"expected --timeout guard message, got: {err}"
);
}
}
4 changes: 2 additions & 2 deletions crates/minvmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ enum Command {
#[arg(long)]
detach: bool,
/// Timeout in seconds to wait for the host UDS when using --detach.
#[arg(long, default_value_t = minvmd::cmd::run::DEFAULT_DETACH_TIMEOUT_SECS)]
timeout: u64,
#[arg(long)]
timeout: Option<u64>,
},
/// Print daemon status (exit 0 if running, 1 if stopped, 2 on lock contention).
Status {
Expand Down