Skip to content

Commit 45b64f2

Browse files
committedMar 27, 2024
Merge branch 'fix-drop-tokio-runtime' into main
2 parents 1dc1bde + a861751 commit 45b64f2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed
 

‎mullvad-daemon/src/main.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ const DAEMON_LOG_FILENAME: &str = "daemon.log";
2222
const EARLY_BOOT_LOG_FILENAME: &str = "early-boot-fw.log";
2323

2424
fn main() {
25-
let exit_code = match run() {
25+
let runtime = new_runtime_builder().build().unwrap_or_else(|e| {
26+
eprintln!("{}", e.display_chain());
27+
std::process::exit(1);
28+
});
29+
30+
let exit_code = match runtime.block_on(run()) {
2631
Ok(_) => 0,
2732
Err(error) => {
2833
if logging::is_enabled() {
@@ -39,37 +44,33 @@ fn main() {
3944
std::process::exit(exit_code);
4045
}
4146

42-
fn run() -> Result<(), String> {
47+
async fn run() -> Result<(), String> {
4348
let config = cli::get_config();
4449

45-
let runtime = new_runtime_builder()
46-
.build()
47-
.map_err(|e| e.display_chain().to_string())?;
48-
4950
match config.command {
5051
cli::Command::Daemon => {
5152
// uniqueness check must happen before logging initializaton,
5253
// as initializing logs will rotate any existing log file.
53-
runtime.block_on(assert_unique())?;
54+
assert_unique().await?;
5455
let log_dir = init_daemon_logging(config)?;
5556
log::trace!("Using configuration: {:?}", config);
5657

57-
runtime.block_on(run_standalone(log_dir))
58+
run_standalone(log_dir).await
5859
}
5960

6061
#[cfg(target_os = "linux")]
6162
cli::Command::InitializeEarlyBootFirewall => {
6263
init_early_boot_logging(config);
6364

64-
runtime
65-
.block_on(crate::early_boot_firewall::initialize_firewall())
65+
crate::early_boot_firewall::initialize_firewall()
66+
.await
6667
.map_err(|err| format!("{err}"))
6768
}
6869

6970
#[cfg(target_os = "windows")]
7071
cli::Command::RunAsService => {
7172
init_logger(config, None)?;
72-
runtime.block_on(assert_unique())?;
73+
assert_unique().await?;
7374
system_service::run()
7475
}
7576

0 commit comments

Comments
 (0)
Failed to load comments.