mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-05 14:11:32 +00:00
krata: implement fast exit code notification
This commit is contained in:
@ -2,6 +2,7 @@ use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use krata::control::control_service_client::ControlServiceClient;
|
||||
|
||||
use tokio::select;
|
||||
use tonic::transport::Channel;
|
||||
|
||||
use crate::{console::StdioConsoleStream, events::EventStream};
|
||||
@ -20,10 +21,17 @@ impl ConsoleCommand {
|
||||
) -> Result<()> {
|
||||
let input = StdioConsoleStream::stdin_stream(self.guest.clone()).await;
|
||||
let output = client.console_data(input).await?.into_inner();
|
||||
let stdout_handle =
|
||||
tokio::task::spawn(async move { StdioConsoleStream::stdout(output).await });
|
||||
let exit_hook_task =
|
||||
StdioConsoleStream::guest_exit_hook(self.guest.clone(), events).await?;
|
||||
StdioConsoleStream::stdout(output).await?;
|
||||
exit_hook_task.abort();
|
||||
Ok(())
|
||||
let code = select! {
|
||||
x = stdout_handle => {
|
||||
x??;
|
||||
None
|
||||
},
|
||||
x = exit_hook_task => x?
|
||||
};
|
||||
std::process::exit(code.unwrap_or(0));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use krata::{
|
||||
},
|
||||
};
|
||||
use log::error;
|
||||
use tokio::select;
|
||||
use tonic::{transport::Channel, Request};
|
||||
|
||||
use crate::{console::StdioConsoleStream, events::EventStream};
|
||||
@ -52,17 +53,25 @@ impl LauchCommand {
|
||||
.await?
|
||||
.into_inner();
|
||||
let id = response.guest_id;
|
||||
if self.attach {
|
||||
let code = if self.attach {
|
||||
wait_guest_started(&id, events.clone()).await?;
|
||||
let input = StdioConsoleStream::stdin_stream(id.clone()).await;
|
||||
let output = client.console_data(input).await?.into_inner();
|
||||
let stdout_handle =
|
||||
tokio::task::spawn(async move { StdioConsoleStream::stdout(output).await });
|
||||
let exit_hook_task = StdioConsoleStream::guest_exit_hook(id.clone(), events).await?;
|
||||
StdioConsoleStream::stdout(output).await?;
|
||||
exit_hook_task.abort();
|
||||
select! {
|
||||
x = stdout_handle => {
|
||||
x??;
|
||||
None
|
||||
},
|
||||
x = exit_hook_task => x?
|
||||
}
|
||||
} else {
|
||||
println!("created guest: {}", id);
|
||||
}
|
||||
Ok(())
|
||||
None
|
||||
};
|
||||
std::process::exit(code.unwrap_or(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user