mirror of
https://github.com/edera-dev/krata.git
synced 2026-04-01 04:10:17 +00:00
controller: implement automatic exit when process has exited
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::{process::exit, time::Duration};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use log::warn;
|
||||
use tokio::time::sleep;
|
||||
use xenstore::client::XsdInterface;
|
||||
|
||||
use super::destroy::ControllerDestroy;
|
||||
use crate::console::XenConsole;
|
||||
|
||||
use super::ControllerContext;
|
||||
@@ -22,7 +28,24 @@ impl ControllerConsole<'_> {
|
||||
let domid = info.domid;
|
||||
let tty = self.context.xen.get_console_path(domid).await?;
|
||||
let console = XenConsole::new(&tty).await?;
|
||||
console.attach().await?;
|
||||
Ok(())
|
||||
|
||||
let dom_path = self.context.xen.store.get_domain_path(domid).await?;
|
||||
|
||||
tokio::task::spawn(async move {
|
||||
if let Err(error) = console.attach().await {
|
||||
warn!("failed to attach to console: {}", error);
|
||||
}
|
||||
});
|
||||
|
||||
let exit_code_path = format!("{}/krata/guest/exit-code", dom_path);
|
||||
loop {
|
||||
let Some(code) = self.context.xen.store.read_string(&exit_code_path).await? else {
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
continue;
|
||||
};
|
||||
let mut destroy = ControllerDestroy::new(self.context);
|
||||
destroy.perform(&domid.to_string()).await?;
|
||||
exit(code.parse::<i32>()?);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user