1- use std:: env:: { self , args} ;
2- use std:: ffi:: CString ;
3- use std:: fs:: { create_dir_all, read_dir, remove_file} ;
4- use std:: io:: { self , IsTerminal , stderr, stdin} ;
5- use std:: path:: { Path , PathBuf } ;
6-
7- use std:: process:: { Command , exit} ;
8- use std:: sync:: { LazyLock , OnceLock } ;
9- use std:: thread;
10- use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
11-
12- mod args;
13- mod config;
14- mod error;
15- mod install_progress;
16- mod lang;
17- mod path_completions;
18- mod pb;
19- mod subcommand;
20- mod table;
21- mod tui;
22- mod utils;
23-
1+ use crate :: config:: Config ;
2+ use crate :: error:: Chain ;
3+ use crate :: install_progress:: osc94_progress;
4+ use crate :: subcommand:: * ;
245use args:: { CliExecuter , OhManagerAilurus } ;
256use clap:: builder:: FalseyValueParser ;
267use clap:: { ArgAction , ArgMatches , Args , ColorChoice , CommandFactory , FromArgMatches , arg} ;
@@ -29,14 +10,27 @@ use clap_i18n_richformatter::{ClapI18nRichFormatter, init_clap_rich_formatter_lo
2910use error:: OutputError ;
3011use i18n_embed:: { DesktopLanguageRequester , Localizer } ;
3112use lang:: LANGUAGE_LOADER ;
13+ use libc:: SIGHUP ;
3214use oma_console:: OmaLayer ;
15+ use oma_console:: console;
3316use oma_console:: print:: { OmaColorFormat , termbg} ;
3417use oma_console:: writer:: { MessageType , Writer , writeln_inner} ;
3518use oma_pm:: apt:: AptConfig ;
3619use oma_utils:: dbus:: { create_dbus_connection, get_another_oma_status} ;
3720use oma_utils:: { OsRelease , is_termux} ;
3821use reqwest:: Client ;
39- use rustix:: stdio:: stdout;
22+ use signal_hook:: consts:: { SIGINT , SIGTERM } ;
23+ use signal_hook:: iterator:: Signals ;
24+ use std:: env:: { self , args} ;
25+ use std:: ffi:: CString ;
26+ use std:: fs:: { create_dir_all, read_dir, remove_file} ;
27+ use std:: io:: { self , IsTerminal , stderr, stdin, stdout} ;
28+ use std:: path:: { Path , PathBuf } ;
29+ use std:: process:: { Command , exit} ;
30+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
31+ use std:: sync:: { LazyLock , OnceLock } ;
32+ use std:: thread;
33+ use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
4034use subcommand:: utils:: { LockError , is_terminal} ;
4135use tokio:: runtime:: Runtime ;
4236use tracing:: { debug, error, info, warn} ;
@@ -47,14 +41,17 @@ use tracing_subscriber::{EnvFilter, Layer, fmt};
4741use tui:: Tui ;
4842use utils:: { is_root, is_ssh_from_loginctl} ;
4943
50- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
51-
52- use oma_console:: console;
53-
54- use crate :: config:: Config ;
55- use crate :: error:: Chain ;
56- use crate :: install_progress:: osc94_progress;
57- use crate :: subcommand:: * ;
44+ mod args;
45+ mod config;
46+ mod error;
47+ mod install_progress;
48+ mod lang;
49+ mod path_completions;
50+ mod pb;
51+ mod subcommand;
52+ mod table;
53+ mod tui;
54+ mod utils;
5855
5956static NOT_DISPLAY_ABORT : AtomicBool = AtomicBool :: new ( false ) ;
6057static LOCKED : AtomicBool = AtomicBool :: new ( false ) ;
@@ -172,7 +169,15 @@ fn main() {
172169 . completer ( "oma" )
173170 . complete ( ) ;
174171
175- ctrlc:: set_handler ( signal_handler) . expect ( "oma could not initialize SIGINT handler." ) ;
172+ thread:: spawn ( || {
173+ let mut sigs =
174+ Signals :: new ( [ SIGTERM , SIGINT , SIGHUP ] ) . expect ( "Failed to set signal handler" ) ;
175+
176+ for signal in & mut sigs {
177+ signal_handler ( ) ;
178+ std:: process:: exit ( 128 + signal)
179+ }
180+ } ) ;
176181
177182 // 要适配额外的插件子命令,所以这里要保留 matches
178183 let ( matches, oma) = parse_args ( ) ;
@@ -703,6 +708,4 @@ fn signal_handler() {
703708 if !not_display_abort {
704709 info ! ( "{}" , fl!( "user-aborted-op" ) ) ;
705710 }
706-
707- std:: process:: exit ( 130 ) ;
708711}
0 commit comments