#![forbid(unsafe_code)]
#[cfg(feature = "musl-allocator")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
fn main() {
#[cfg(not(debug_assertions))]
human_panic::setup_panic!();
if let Err(e) = ssh_cli::tls::install_default_provider() {
let _ = ssh_cli::output::print_error_fmt(format_args!(
"failed to install rustls CryptoProvider: {e}"
));
std::process::exit(ssh_cli::errors::exit_codes::EX_IOERR);
}
if let Err(e) = ssh_cli::signals::register_handler() {
let _ = ssh_cli::output::print_error_fmt(format_args!(
"failed to register signal handlers: {e}"
));
std::process::exit(ssh_cli::errors::exit_codes::EX_IOERR);
}
let workers = ssh_cli::concurrency::worker_threads();
let max_blocking = ssh_cli::concurrency::max_blocking_threads();
let runtime = match tokio::runtime::Builder::new_multi_thread()
.worker_threads(workers)
.max_blocking_threads(max_blocking)
.thread_name("ssh-cli-worker")
.enable_all()
.build()
{
Ok(rt) => rt,
Err(e) => {
let _ = ssh_cli::output::print_error_fmt(format_args!(
"failed to create runtime: {e}"
));
std::process::exit(ssh_cli::errors::exit_codes::EX_IOERR);
}
};
let result = runtime.block_on(ssh_cli::run());
let _ = std::io::Write::flush(&mut std::io::stdout());
let code = ssh_cli::resolve_exit_code(result);
runtime.shutdown_timeout(std::time::Duration::from_secs(
ssh_cli::constants::RUNTIME_SHUTDOWN_TIMEOUT_SECS,
));
std::process::exit(code);
}