mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 21:21:32 +00:00
krata: event-based network backend startup and api enhancements
This commit is contained in:
@ -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(())
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user