use clap::Parser;
#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
use tikv_jemallocator::Jemalloc;
use tokio::runtime;
use tracing::{Level, info};
use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt};
use hickory_dns::DnsServer;
fn main() -> Result<(), String> {
if let Err(e) = run() {
eprintln!("Error: {e}");
std::process::exit(1);
}
Ok(())
}
fn run() -> Result<(), String> {
let args = DnsServer::parse();
let level = match (args.quiet, args.debug) {
(true, _) => Level::ERROR,
(_, true) => Level::DEBUG,
_ => Level::INFO,
};
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(
EnvFilter::builder()
.with_default_directive(level.into())
.from_env()
.map_err(|err| {
format!("failed to parse environment variable for tracing: {err}")
})?,
)
.init();
info!("Hickory DNS {} starting...", env!("CARGO_PKG_VERSION"));
let mut runtime = runtime::Builder::new_multi_thread();
runtime.enable_all().thread_name("hickory-server-runtime");
if let Some(workers) = args.workers {
runtime.worker_threads(workers);
}
let runtime = runtime
.build()
.map_err(|err| format!("failed to initialize Tokio runtime: {err}"))?;
runtime.block_on(args.run())
}
#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;