43
43
#[ cfg( not( target_arch = "wasm32" ) ) ] use common:: block_on;
44
44
use common:: crash_reports:: init_crash_reports;
45
45
use common:: double_panic_crash;
46
+ use common:: executor:: SpawnFuture ;
47
+ use common:: log;
46
48
use common:: log:: LogLevel ;
47
49
use common:: password_policy:: password_policy;
48
50
use mm2_core:: mm_ctx:: MmCtxBuilder ;
@@ -54,7 +56,6 @@ use lp_swap::PAYMENT_LOCKTIME;
54
56
use std:: sync:: atomic:: Ordering ;
55
57
56
58
use gstuff:: slurp;
57
-
58
59
use serde:: ser:: Serialize ;
59
60
use serde_json:: { self as json, Value as Json } ;
60
61
@@ -64,7 +65,6 @@ use std::process::exit;
64
65
use std:: ptr:: null;
65
66
use std:: str;
66
67
67
- mod lp_native_dex;
68
68
pub use self :: lp_native_dex:: init_hw;
69
69
pub use self :: lp_native_dex:: lp_init;
70
70
use coins:: update_coins_config;
@@ -75,6 +75,7 @@ use mm2_err_handle::prelude::*;
75
75
pub mod heartbeat_event;
76
76
pub mod lp_dispatcher;
77
77
pub mod lp_message_service;
78
+ mod lp_native_dex;
78
79
pub mod lp_network;
79
80
pub mod lp_ordermatch;
80
81
pub mod lp_stats;
@@ -160,10 +161,28 @@ pub async fn lp_main(
160
161
. with_datetime ( datetime. clone ( ) )
161
162
. into_mm_arc ( ) ;
162
163
ctx_cb ( try_s ! ( ctx. ffi_handle( ) ) ) ;
164
+
165
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
166
+ spawn_ctrl_c_handler ( ctx. clone ( ) ) ;
167
+
163
168
try_s ! ( lp_init( ctx, version, datetime) . await ) ;
164
169
Ok ( ( ) )
165
170
}
166
171
172
+ /// Handles CTRL-C signals and shutdowns the KDF runtime gracefully.
173
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
174
+ fn spawn_ctrl_c_handler ( ctx : mm2_core:: mm_ctx:: MmArc ) {
175
+ ctx. spawner ( ) . spawn ( async move {
176
+ tokio:: signal:: ctrl_c ( )
177
+ . await
178
+ . expect ( "Couldn't listen for the CTRL-C signal." ) ;
179
+
180
+ log:: info!( "Wrapping things up and shutting down..." ) ;
181
+
182
+ ctx. stop ( ) . await . expect ( "Couldn't stop the KDF runtime." ) ;
183
+ } ) ;
184
+ }
185
+
167
186
fn help ( ) {
168
187
const HELP_MSG : & str = r#"Command-line options.
169
188
The first command-line argument is special and designates the mode.
0 commit comments