@@ -62,14 +62,31 @@ struct Cli {
6262 detached : bool ,
6363}
6464
65- #[ tokio:: main]
66- async fn main ( ) -> Result < ( ) > {
65+ fn main ( ) {
66+ let args = Cli :: parse ( ) ;
67+ #[ cfg( not( target_os = "windows" ) ) ]
68+ {
69+ if args. detached {
70+ let daemonize = daemonize:: Daemonize :: new ( ) ;
71+ if let Err ( e) = daemonize. start ( ) {
72+ eprintln ! ( "Error: {}" , e) ;
73+ }
74+ }
75+ }
76+
77+ tokio:: runtime:: Builder :: new_multi_thread ( )
78+ . enable_all ( )
79+ . build ( )
80+ . expect ( "Failed to build tokio runtime" )
81+ . block_on ( main_entry ( args) )
82+ . expect ( "Failed to run program" )
83+ }
84+
85+ async fn main_entry ( args : Cli ) -> Result < ( ) > {
6786 let filter = EnvFilter :: try_from_default_env ( ) . unwrap_or_else ( |_| EnvFilter :: new ( "sthp=debug" ) ) ;
6887 tracing_subscriber:: fmt ( ) . with_env_filter ( filter) . init ( ) ;
6988 color_eyre:: install ( ) ?;
7089
71- let args = Cli :: parse ( ) ;
72-
7390 let socks_addr = args. socks_address ;
7491 let port = args. port ;
7592 let auth_details = args
@@ -88,16 +105,6 @@ async fn main() -> Result<()> {
88105
89106 let listener = TcpListener :: bind ( addr) . await ?;
90107
91- #[ cfg( not( target_os = "windows" ) ) ]
92- {
93- if args. detached {
94- let daemonize = daemonize:: Daemonize :: new ( ) ;
95- if let Err ( e) = daemonize. start ( ) {
96- eprintln ! ( "Error: {}" , e) ;
97- }
98- }
99- }
100-
101108 info ! ( "Listening on http://{}" , addr) ;
102109
103110 loop {
0 commit comments