Skip to content
Open
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
5 changes: 5 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ The URI (address) of the RESTful service. If not specified, defaults to `none://

Specify a path in which krunkit will write the PID to. The option does not provide any form of locking.

- `--reset-exit-code`

Exit with this code when the guest resets, so the caller can tell a reboot from a power-off and start the virtual
machine again. Without the option, krunkit exits with 0 in both cases. Requires libkrun 1.19.8 or newer.

- `--timesync`

Specify a Vsock port on which the host will send the current time to
Expand Down
9 changes: 9 additions & 0 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ pub struct Args {
#[arg(long, short)]
pub nested: bool,

/// Exit with this code when the guest resets, so the caller can tell a reboot from a
/// power-off and start the VM again. Without it both end krunkit with exit code 0.
#[arg(long = "reset-exit-code")]
pub reset_exit_code: Option<u8>,

/// Specify a pidfile path.
#[arg(long)]
pub pidfile: Option<PathBuf>,
Expand Down Expand Up @@ -533,13 +538,17 @@ mod tests {
"5",
"--pidfile",
"/tmp/krunkit.pid",
"--reset-exit-code",
"32",
];

let mut args = Args::try_parse_from(cmdline).unwrap();

let pidfile = args.pidfile.expect("pidfile argument not found");
assert_eq!(pidfile.to_str().unwrap(), "/tmp/krunkit.pid");

assert_eq!(args.reset_exit_code, Some(32));

let net = args
.devices
.pop()
Expand Down
7 changes: 7 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" {
fn krun_set_smbios_oem_strings(ctx_id: u32, oem_strings: *const *const c_char) -> i32;
fn krun_set_nested_virt(ctx_id: u32, enabled: bool) -> i32;
fn krun_check_nested_virt() -> i32;
fn krun_set_reset_exit_code(ctx_id: u32, code: u8) -> i32;
fn krun_start_enter(ctx_id: u32) -> i32;
}

Expand Down Expand Up @@ -187,6 +188,12 @@ impl TryFrom<Args> for KrunContext {

set_smbios_oem_strings(id, &args.oem_strings)?;

if let Some(code) = args.reset_exit_code {
if unsafe { krun_set_reset_exit_code(id, code) } < 0 {
return Err(anyhow!("unable to set the reset exit code"));
}
}

if args.nested {
match unsafe { krun_check_nested_virt() } {
1 => {
Expand Down