@@ -22,7 +22,12 @@ const DAEMON_LOG_FILENAME: &str = "daemon.log";
22
22
const EARLY_BOOT_LOG_FILENAME : & str = "early-boot-fw.log" ;
23
23
24
24
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 ( ) ) {
26
31
Ok ( _) => 0 ,
27
32
Err ( error) => {
28
33
if logging:: is_enabled ( ) {
@@ -39,37 +44,33 @@ fn main() {
39
44
std:: process:: exit ( exit_code) ;
40
45
}
41
46
42
- fn run ( ) -> Result < ( ) , String > {
47
+ async fn run ( ) -> Result < ( ) , String > {
43
48
let config = cli:: get_config ( ) ;
44
49
45
- let runtime = new_runtime_builder ( )
46
- . build ( )
47
- . map_err ( |e| e. display_chain ( ) . to_string ( ) ) ?;
48
-
49
50
match config. command {
50
51
cli:: Command :: Daemon => {
51
52
// uniqueness check must happen before logging initializaton,
52
53
// as initializing logs will rotate any existing log file.
53
- runtime . block_on ( assert_unique ( ) ) ?;
54
+ assert_unique ( ) . await ?;
54
55
let log_dir = init_daemon_logging ( config) ?;
55
56
log:: trace!( "Using configuration: {:?}" , config) ;
56
57
57
- runtime . block_on ( run_standalone ( log_dir) )
58
+ run_standalone ( log_dir) . await
58
59
}
59
60
60
61
#[ cfg( target_os = "linux" ) ]
61
62
cli:: Command :: InitializeEarlyBootFirewall => {
62
63
init_early_boot_logging ( config) ;
63
64
64
- runtime
65
- . block_on ( crate :: early_boot_firewall :: initialize_firewall ( ) )
65
+ crate :: early_boot_firewall :: initialize_firewall ( )
66
+ . await
66
67
. map_err ( |err| format ! ( "{err}" ) )
67
68
}
68
69
69
70
#[ cfg( target_os = "windows" ) ]
70
71
cli:: Command :: RunAsService => {
71
72
init_logger ( config, None ) ?;
72
- runtime . block_on ( assert_unique ( ) ) ?;
73
+ assert_unique ( ) . await ?;
73
74
system_service:: run ( )
74
75
}
75
76
0 commit comments