mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 04:34:27 +00:00
main: Refactor main logic into new async function
Move most of the main logic into a separate async function. This makes the code clearer and avoids the anonymous async block. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
2a648fa760
commit
039df1d727
@ -121,31 +121,7 @@ async fn get_vsock_stream(fd: RawFd) -> Result<VsockStream> {
|
|||||||
Ok(stream)
|
Ok(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
async fn real_main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
let args: Vec<String> = env::args().collect();
|
|
||||||
|
|
||||||
if args.len() == 2 && args[1] == "--version" {
|
|
||||||
println!(
|
|
||||||
"{} version {} (api version: {}, commit version: {}, type: rust)",
|
|
||||||
NAME,
|
|
||||||
version::AGENT_VERSION,
|
|
||||||
version::API_VERSION,
|
|
||||||
version::VERSION_COMMIT,
|
|
||||||
);
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if args.len() == 2 && args[1] == "init" {
|
|
||||||
rustjail::container::init_child();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
|
||||||
.enable_all()
|
|
||||||
.build()?;
|
|
||||||
|
|
||||||
rt.block_on(async {
|
|
||||||
env::set_var("RUST_BACKTRACE", "full");
|
env::set_var("RUST_BACKTRACE", "full");
|
||||||
|
|
||||||
lazy_static::initialize(&SHELLS);
|
lazy_static::initialize(&SHELLS);
|
||||||
@ -245,7 +221,33 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||||||
let _ = log_handle.await.unwrap();
|
let _ = log_handle.await.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
}
|
||||||
|
|
||||||
|
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
if args.len() == 2 && args[1] == "--version" {
|
||||||
|
println!(
|
||||||
|
"{} version {} (api version: {}, commit version: {}, type: rust)",
|
||||||
|
NAME,
|
||||||
|
version::AGENT_VERSION,
|
||||||
|
version::API_VERSION,
|
||||||
|
version::VERSION_COMMIT,
|
||||||
|
);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if args.len() == 2 && args[1] == "init" {
|
||||||
|
rustjail::container::init_child();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
|
.enable_all()
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
rt.block_on(real_main())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_sandbox(logger: &Logger, config: &AgentConfig, init_mode: bool) -> Result<()> {
|
async fn start_sandbox(logger: &Logger, config: &AgentConfig, init_mode: bool) -> Result<()> {
|
||||||
|
Loading…
Reference in New Issue
Block a user