mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 13:11:31 +00:00
controller: implement automatic exit when process has exited
This commit is contained in:
@ -5,7 +5,7 @@ use std::{
|
||||
|
||||
use anyhow::Result;
|
||||
use futures::future::join_all;
|
||||
use log::warn;
|
||||
use log::debug;
|
||||
use std::process::exit;
|
||||
use termion::raw::IntoRawMode;
|
||||
use tokio::{
|
||||
@ -34,7 +34,7 @@ impl XenConsole {
|
||||
let stdout = unsafe { File::from_raw_fd(terminal.as_raw_fd()) };
|
||||
let reader_task = tokio::task::spawn(async move {
|
||||
if let Err(error) = XenConsole::copy_stdout(stdout, self.xen_read_handle).await {
|
||||
warn!("failed to copy console output: {}", error);
|
||||
debug!("failed to copy console output: {}", error);
|
||||
}
|
||||
});
|
||||
let writer_task = tokio::task::spawn(async move {
|
||||
@ -44,7 +44,7 @@ impl XenConsole {
|
||||
)
|
||||
.await
|
||||
{
|
||||
warn!("failed to intercept stdin: {}", error);
|
||||
debug!("failed to intercept stdin: {}", error);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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