@@ -2,6 +2,7 @@ use std::env::{self, args};
22use std:: ffi:: CString ;
33use std:: fs:: { create_dir_all, read_dir, remove_file} ;
44use std:: io:: { self , IsTerminal , stderr, stdin} ;
5+ use std:: os:: raw:: c_int;
56use std:: path:: { Path , PathBuf } ;
67
78use std:: process:: { Command , exit} ;
@@ -37,6 +38,7 @@ use oma_utils::dbus::{create_dbus_connection, get_another_oma_status};
3738use oma_utils:: { OsRelease , is_termux} ;
3839use reqwest:: Client ;
3940use rustix:: stdio:: stdout;
41+ use signal_hook:: iterator:: Signals ;
4042use subcommand:: utils:: { LockError , is_terminal} ;
4143use tokio:: runtime:: Runtime ;
4244use tracing:: { debug, error, info, warn} ;
@@ -55,6 +57,9 @@ use crate::config::Config;
5557use crate :: error:: Chain ;
5658use crate :: install_progress:: osc94_progress;
5759use crate :: subcommand:: * ;
60+ use signal_hook:: consts:: * ;
61+
62+ const SIGNALS : & [ c_int ] = & [ SIGTERM , SIGQUIT , SIGINT , SIGTSTP , SIGWINCH , SIGHUP , SIGCONT ] ;
5863
5964static NOT_DISPLAY_ABORT : AtomicBool = AtomicBool :: new ( false ) ;
6065static LOCKED : AtomicBool = AtomicBool :: new ( false ) ;
@@ -172,7 +177,14 @@ fn main() {
172177 . completer ( "oma" )
173178 . complete ( ) ;
174179
175- ctrlc:: set_handler ( single_handler) . expect ( "oma could not initialize SIGINT handler." ) ;
180+ thread:: spawn ( || {
181+ let Ok ( mut sigs) = Signals :: new ( SIGNALS ) else {
182+ panic ! ( "Failed to set signal handler." )
183+ } ;
184+ for _ in & mut sigs {
185+ single_handler ( ) ;
186+ }
187+ } ) ;
176188
177189 // 要适配额外的插件子命令,所以这里要保留 matches
178190 let ( matches, oma) = parse_args ( ) ;
0 commit comments