()
| 73 | } |
| 74 | |
| 75 | fn main() -> Result<()> { |
| 76 | // Set max ulimit for file descriptors |
| 77 | #[cfg(unix)] |
| 78 | if let Err(err) = set_max_ulimit() { |
| 79 | error!("Failed to set max ulimit: {err:?}"); |
| 80 | } |
| 81 | |
| 82 | let args = Args::parse(); |
| 83 | if let Some(log_file) = &args.log_file { |
| 84 | mk_parents(log_file)?; |
| 85 | let file = std::fs::OpenOptions::new() |
| 86 | .create(true) |
| 87 | .append(true) |
| 88 | .open(log_file) |
| 89 | .context("Failed to open log file")?; |
| 90 | tracing_subscriber::fmt() |
| 91 | .with_env_filter(EnvFilter::from_default_env()) |
| 92 | .with_writer(file) |
| 93 | .with_ansi(false) |
| 94 | .init(); |
| 95 | } else { |
| 96 | tracing_subscriber::fmt() |
| 97 | .with_env_filter(EnvFilter::from_default_env()) |
| 98 | .with_ansi(false) |
| 99 | .init(); |
| 100 | } |
| 101 | #[cfg(unix)] |
| 102 | if args.detach { |
| 103 | // run in background |
| 104 | let ret = unsafe { libc::daemon(1, 0) }; |
| 105 | if ret != 0 { |
| 106 | error!("Failed to run in background, error code: {ret}"); |
| 107 | bail!("Failed to run in background, error code: {ret}"); |
| 108 | } |
| 109 | } |
| 110 | if let Err(err) = async_main(args) { |
| 111 | error!("{err:?}"); |
| 112 | return Err(err); |
| 113 | } |
| 114 | Ok(()) |
| 115 | } |
| 116 | |
| 117 | #[tokio::main] |
| 118 | async fn async_main(args: Args) -> Result<()> { |
nothing calls this directly
no test coverage detected