File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ pub struct CoreParams {
3838 pub directory : String ,
3939 pub hostname : String ,
4040 pub pathname : String ,
41+ pub timeout : u64 ,
4142 pub namespace : Option < String > ,
4243 pub podname : Option < String > ,
4344 pub uuid : Uuid ,
@@ -56,6 +57,12 @@ impl CoreConfig {
5657 let directory = matches. value_of ( "directory" ) . unwrap_or ( "" ) . to_string ( ) ;
5758 let hostname = matches. value_of ( "hostname" ) . unwrap_or ( "" ) . to_string ( ) ;
5859 let pathname = matches. value_of ( "pathname" ) . unwrap_or ( "" ) . to_string ( ) ;
60+ let timeout = matches
61+ . value_of ( "timeout" )
62+ . unwrap_or ( "60" )
63+ . parse :: < u64 > ( )
64+ . unwrap ( ) ;
65+
5966 let uuid = Uuid :: new_v4 ( ) ;
6067
6168 let params = CoreParams {
@@ -67,6 +74,7 @@ impl CoreConfig {
6774 directory,
6875 hostname,
6976 pathname,
77+ timeout,
7078 namespace : None ,
7179 podname : None ,
7280 uuid,
@@ -292,6 +300,14 @@ pub fn try_get_matches() -> clap::Result<ArgMatches> {
292300 . takes_value ( true )
293301 . help ( "Hostname (same as nodename returned by uname(2))" ) ,
294302 )
303+ . arg (
304+ Arg :: new ( "timeout" )
305+ . short ( 'T' )
306+ . long ( "timeout" )
307+ . required ( false )
308+ . takes_value ( true )
309+ . help ( "Timeout in seconds to wait for processing of the Coredump" ) ,
310+ )
295311 . arg (
296312 Arg :: new ( "test-threads" )
297313 . long ( "test-threads" )
Original file line number Diff line number Diff line change @@ -9,14 +9,34 @@ use std::fs::File;
99use std:: io;
1010use std:: io:: prelude:: * ;
1111use std:: process;
12+ use std:: sync:: mpsc:: channel;
13+ use std:: thread;
14+ use std:: time:: Duration ;
1215use zip:: write:: FileOptions ;
1316use zip:: ZipWriter ;
1417
1518mod config;
1619mod logging;
1720
1821fn main ( ) -> Result < ( ) , anyhow:: Error > {
19- let mut cc = config:: CoreConfig :: new ( ) ?;
22+ let ( send, recv) = channel ( ) ;
23+ let cc = config:: CoreConfig :: new ( ) ?;
24+ let timeout = cc. params . timeout . clone ( ) ;
25+
26+ thread:: spawn ( move || {
27+ let result = handle ( cc) ;
28+ send. send ( result) . unwrap ( ) ;
29+ } ) ;
30+
31+ let result = recv. recv_timeout ( Duration :: from_secs ( timeout) ) ;
32+
33+ match result {
34+ Ok ( inner_result) => inner_result,
35+ Err ( error) => panic ! ( "Timeout: {}" , error) ,
36+ }
37+ }
38+
39+ fn handle ( mut cc : config:: CoreConfig ) -> Result < ( ) , anyhow:: Error > {
2040 cc. set_namespace ( "default" . to_string ( ) ) ;
2141 let l_log_level = cc. log_level . clone ( ) ;
2242 let log_path = logging:: init_logger ( l_log_level) ?;
You can’t perform that action at this time.
0 commit comments