File tree Expand file tree Collapse file tree 3 files changed +20
-9
lines changed Expand file tree Collapse file tree 3 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,10 @@ mod init {
89
89
///
90
90
/// It will abort the process on second press and won't inform the user about this behaviour either as we are unable to do so without
91
91
/// deadlocking even when trying to write to stderr directly.
92
- pub fn init_handler (
92
+ ///
93
+ /// SAFETY: `interrupt()` will be called from a signal handler. See `signal_hook::low_level::register()` for details about.
94
+ #[ allow( unsafe_code) ]
95
+ pub unsafe fn init_handler (
93
96
grace_count : usize ,
94
97
interrupt : impl Fn ( ) + Send + Sync + Clone + ' static ,
95
98
) -> io:: Result < Deregister > {
Original file line number Diff line number Diff line change @@ -136,10 +136,14 @@ pub fn main() -> Result<()> {
136
136
let auto_verbose = !progress && !args. no_verbose ;
137
137
138
138
let should_interrupt = Arc :: new ( AtomicBool :: new ( false ) ) ;
139
- gix:: interrupt:: init_handler ( 1 , {
140
- let should_interrupt = Arc :: clone ( & should_interrupt) ;
141
- move || should_interrupt. store ( true , Ordering :: SeqCst )
142
- } ) ?;
139
+ #[ allow( unsafe_code) ]
140
+ unsafe {
141
+ // SAFETY: The closure doesn't use mutexes or memory allocation, so it should be safe to call from a signal handler.
142
+ gix:: interrupt:: init_handler ( 1 , {
143
+ let should_interrupt = Arc :: clone ( & should_interrupt) ;
144
+ move || should_interrupt. store ( true , Ordering :: SeqCst )
145
+ } ) ?;
146
+ }
143
147
144
148
match cmd {
145
149
Subcommands :: Status ( crate :: plumbing:: options:: status:: Platform {
Original file line number Diff line number Diff line change @@ -18,10 +18,14 @@ pub fn main() -> Result<()> {
18
18
time:: util:: local_offset:: set_soundness ( time:: util:: local_offset:: Soundness :: Unsound ) ;
19
19
}
20
20
let should_interrupt = Arc :: new ( AtomicBool :: new ( false ) ) ;
21
- gix:: interrupt:: init_handler ( 1 , {
22
- let should_interrupt = Arc :: clone ( & should_interrupt) ;
23
- move || should_interrupt. store ( true , Ordering :: SeqCst )
24
- } ) ?;
21
+ #[ allow( unsafe_code) ]
22
+ unsafe {
23
+ // SAFETY: The closure doesn't use mutexes or memory allocation, so it should be safe to call from a signal handler.
24
+ gix:: interrupt:: init_handler ( 1 , {
25
+ let should_interrupt = Arc :: clone ( & should_interrupt) ;
26
+ move || should_interrupt. store ( true , Ordering :: SeqCst )
27
+ } ) ?;
28
+ }
25
29
let trace = false ;
26
30
let verbose = !args. quiet ;
27
31
let progress = args. progress ;
You can’t perform that action at this time.
0 commit comments