File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ pub struct CoreParams {
38
38
pub directory : String ,
39
39
pub hostname : String ,
40
40
pub pathname : String ,
41
+ pub timeout : u64 ,
41
42
pub namespace : Option < String > ,
42
43
pub podname : Option < String > ,
43
44
pub uuid : Uuid ,
@@ -56,6 +57,12 @@ impl CoreConfig {
56
57
let directory = matches. value_of ( "directory" ) . unwrap_or ( "" ) . to_string ( ) ;
57
58
let hostname = matches. value_of ( "hostname" ) . unwrap_or ( "" ) . to_string ( ) ;
58
59
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
+
59
66
let uuid = Uuid :: new_v4 ( ) ;
60
67
61
68
let params = CoreParams {
@@ -67,6 +74,7 @@ impl CoreConfig {
67
74
directory,
68
75
hostname,
69
76
pathname,
77
+ timeout,
70
78
namespace : None ,
71
79
podname : None ,
72
80
uuid,
@@ -292,6 +300,14 @@ pub fn try_get_matches() -> clap::Result<ArgMatches> {
292
300
. takes_value ( true )
293
301
. help ( "Hostname (same as nodename returned by uname(2))" ) ,
294
302
)
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
+ )
295
311
. arg (
296
312
Arg :: new ( "test-threads" )
297
313
. long ( "test-threads" )
Original file line number Diff line number Diff line change @@ -9,14 +9,34 @@ use std::fs::File;
9
9
use std:: io;
10
10
use std:: io:: prelude:: * ;
11
11
use std:: process;
12
+ use std:: sync:: mpsc:: channel;
13
+ use std:: thread;
14
+ use std:: time:: Duration ;
12
15
use zip:: write:: FileOptions ;
13
16
use zip:: ZipWriter ;
14
17
15
18
mod config;
16
19
mod logging;
17
20
18
21
fn 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 > {
20
40
cc. set_namespace ( "default" . to_string ( ) ) ;
21
41
let l_log_level = cc. log_level . clone ( ) ;
22
42
let log_path = logging:: init_logger ( l_log_level) ?;
You can’t perform that action at this time.
0 commit comments