krata: event-based network backend startup and api enhancements

This commit is contained in:
Alex Zenla
2024-03-27 02:54:39 +00:00
parent 63c0feb053
commit 66465793cd
29 changed files with 346 additions and 229 deletions

View File

@ -1,6 +1,7 @@
use anyhow::{anyhow, Result};
use env_logger::Env;
use krataguest::init::GuestInit;
use krataguest::{death, init::GuestInit};
use log::error;
use std::env;
#[tokio::main]
@ -19,6 +20,9 @@ async fn main() -> Result<()> {
}
}
let mut guest = GuestInit::new();
guest.init().await?;
if let Err(error) = guest.init().await {
error!("failed to initialize guest: {}", error);
death(127).await?;
}
Ok(())
}

View File

@ -1,10 +1,10 @@
use std::time::Duration;
use crate::childwait::{ChildEvent, ChildWait};
use crate::{
childwait::{ChildEvent, ChildWait},
death,
};
use anyhow::Result;
use nix::{libc::c_int, unistd::Pid};
use tokio::{select, time::sleep};
use xenstore::{XsdClient, XsdInterface};
use nix::unistd::Pid;
use tokio::select;
pub struct GuestBackground {
child: Pid,
@ -35,19 +35,8 @@ impl GuestBackground {
async fn child_event(&mut self, event: ChildEvent) -> Result<()> {
if event.pid == self.child {
self.death(event.status).await?;
death(event.status).await?;
}
Ok(())
}
async fn death(&mut self, code: c_int) -> Result<()> {
let store = XsdClient::open().await?;
store
.write_string("krata/guest/exit-code", &code.to_string())
.await?;
drop(store);
loop {
sleep(Duration::from_secs(1)).await;
}
}
}

View File

@ -1,3 +1,20 @@
use std::{os::raw::c_int, time::Duration};
use anyhow::Result;
use tokio::time::sleep;
use xenstore::{XsdClient, XsdInterface};
pub mod background;
pub mod childwait;
pub mod init;
pub async fn death(code: c_int) -> Result<()> {
let store = XsdClient::open().await?;
store
.write_string("krata/guest/exit-code", &code.to_string())
.await?;
drop(store);
loop {
sleep(Duration::from_secs(1)).await;
}
}