@@ -8,7 +8,9 @@ use std::{
88 io,
99 path:: Path ,
1010 process:: Command ,
11- thread,
11+ sync:: Arc ,
12+ thread:: { self , sleep} ,
13+ time:: Duration ,
1214} ;
1315
1416use anyhow:: Context as _;
@@ -90,11 +92,10 @@ fn main() -> anyhow::Result<()> {
9092 log:: info!(
9193 "Detected versions: Systemd {sd_version}, Linux kernel {kernel_version}, strace {strace_version}"
9294 ) ;
93- if strace_version < strace:: StraceVersion :: new ( 6 , 4 ) {
94- log:: warn!(
95- "Strace version >=6.4 is strongly recommended, if you experience strace output parsing errors, please consider upgrading"
96- ) ;
97- }
95+ anyhow:: ensure!(
96+ strace_version >= strace:: StraceVersion :: new( 6 , 6 ) ,
97+ "Strace version >=6.6 is required"
98+ ) ;
9899
99100 // Parse cl args
100101 let args = cl:: Args :: parse ( ) ;
@@ -122,17 +123,30 @@ fn main() -> anyhow::Result<()> {
122123 & hardening_opts,
123124 ) ;
124125
126+ // Run strace
127+ let cmd = command. iter ( ) . map ( |a| & * * a) . collect :: < Vec < & str > > ( ) ;
128+ let st = Arc :: new (
129+ strace:: Strace :: run ( & cmd, strace_log_path)
130+ . context ( "Failed to setup strace profiling" ) ?,
131+ ) ;
132+
125133 // Start signal handling thread
126134 let mut signals = signal_hook:: iterator:: Signals :: new ( [
127135 signal_hook:: consts:: signal:: SIGINT ,
128136 signal_hook:: consts:: signal:: SIGQUIT ,
129137 signal_hook:: consts:: signal:: SIGTERM ,
130138 ] )
131139 . context ( "Failed to setup signal handlers" ) ?;
140+ let st_sig = Arc :: clone ( & st) ;
132141 thread:: spawn ( move || {
133142 for sig in signals. forever ( ) {
134- // The strace, and its watched child processes already get the signal, so the iterator will stop naturally
135- log:: info!( "Got signal {sig:?}, ignoring" ) ;
143+ // Propagate signal to strace after this delay, in most cases everything should have already stopped
144+ const SIGNAL_STRACE_STOP_DELAY : Duration = Duration :: from_secs ( 5 ) ;
145+
146+ log:: info!( "Got signal {sig:?}" ) ;
147+ sleep ( SIGNAL_STRACE_STOP_DELAY ) ;
148+ log:: info!( "Stopping strace" ) ;
149+ st_sig. stop ( ) ;
136150 }
137151 } ) ;
138152
@@ -146,11 +160,6 @@ fn main() -> anyhow::Result<()> {
146160 env:: current_dir ( ) . context ( "Failed to read current directory" ) ?,
147161 ) ;
148162
149- // Run strace
150- let cmd = command. iter ( ) . map ( |a| & * * a) . collect :: < Vec < & str > > ( ) ;
151- let st = strace:: Strace :: run ( & cmd, strace_log_path)
152- . context ( "Failed to setup strace profiling" ) ?;
153-
154163 // Summarize actions
155164 let logs = st
156165 . log_lines ( )
0 commit comments