mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 13:11:31 +00:00
krata: fix exit status when guest exit happens during attach
This commit is contained in:
@ -10,6 +10,7 @@ env_logger = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
ipnetwork = { workspace = true }
|
||||
krata = { path = "../krata" }
|
||||
libc = { workspace = true }
|
||||
log = { workspace = true }
|
||||
nix = { workspace = true, features = ["process"] }
|
||||
oci-spec = { workspace = true }
|
||||
|
@ -6,14 +6,14 @@ use nix::{libc::c_int, unistd::Pid};
|
||||
use tokio::{select, time::sleep};
|
||||
use xenstore::{XsdClient, XsdInterface};
|
||||
|
||||
pub struct ContainerBackground {
|
||||
pub struct GuestBackground {
|
||||
child: Pid,
|
||||
wait: ChildWait,
|
||||
}
|
||||
|
||||
impl ContainerBackground {
|
||||
pub async fn new(child: Pid) -> Result<ContainerBackground> {
|
||||
Ok(ContainerBackground {
|
||||
impl GuestBackground {
|
||||
pub async fn new(child: Pid) -> Result<GuestBackground> {
|
||||
Ok(GuestBackground {
|
||||
child,
|
||||
wait: ChildWait::new()?,
|
||||
})
|
||||
|
@ -8,11 +8,9 @@ use std::{
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use libc::{c_int, waitpid, WEXITSTATUS, WIFEXITED};
|
||||
use log::warn;
|
||||
use nix::{
|
||||
libc::{c_int, wait},
|
||||
unistd::Pid,
|
||||
};
|
||||
use nix::unistd::Pid;
|
||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||
|
||||
const CHILD_WAIT_QUEUE_LEN: usize = 10;
|
||||
@ -63,15 +61,18 @@ impl ChildWaitTask {
|
||||
fn process(&mut self) -> Result<()> {
|
||||
loop {
|
||||
let mut status: c_int = 0;
|
||||
let pid = unsafe { wait(addr_of_mut!(status)) };
|
||||
let event = ChildEvent {
|
||||
pid: Pid::from_raw(pid),
|
||||
status,
|
||||
};
|
||||
let _ = self.sender.try_send(event);
|
||||
let pid = unsafe { waitpid(-1, addr_of_mut!(status), 0) };
|
||||
|
||||
if self.signal.load(Ordering::Acquire) {
|
||||
return Ok(());
|
||||
if WIFEXITED(status) {
|
||||
let event = ChildEvent {
|
||||
pid: Pid::from_raw(pid),
|
||||
status: WEXITSTATUS(status),
|
||||
};
|
||||
let _ = self.sender.try_send(event);
|
||||
|
||||
if self.signal.load(Ordering::Acquire) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use std::{fs, io};
|
||||
use sys_mount::{FilesystemType, Mount, MountFlags};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::background::ContainerBackground;
|
||||
use crate::background::GuestBackground;
|
||||
|
||||
const IMAGE_BLOCK_DEVICE_PATH: &str = "/dev/xvda";
|
||||
const CONFIG_BLOCK_DEVICE_PATH: &str = "/dev/xvdb";
|
||||
@ -516,7 +516,7 @@ impl GuestInit {
|
||||
}
|
||||
|
||||
async fn background(&mut self, executed: Pid) -> Result<()> {
|
||||
let mut background = ContainerBackground::new(executed).await?;
|
||||
let mut background = GuestBackground::new(executed).await?;
|
||||
background.run().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user