Skip to content

Commit

Permalink
Implement timeout handling
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Buchwaldt <tim@buchwaldt.ws>
  • Loading branch information
timbuchwaldt committed Sep 12, 2022
1 parent 2386e91 commit 3631086
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
16 changes: 16 additions & 0 deletions core-dump-composer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct CoreParams {
pub directory: String,
pub hostname: String,
pub pathname: String,
pub timeout: u64,
pub namespace: Option<String>,
pub podname: Option<String>,
pub uuid: Uuid,
Expand All @@ -56,6 +57,12 @@ impl CoreConfig {
let directory = matches.value_of("directory").unwrap_or("").to_string();
let hostname = matches.value_of("hostname").unwrap_or("").to_string();
let pathname = matches.value_of("pathname").unwrap_or("").to_string();
let timeout = matches
.value_of("timeout")
.unwrap_or("60")
.parse::<u64>()
.unwrap();

let uuid = Uuid::new_v4();

let params = CoreParams {
Expand All @@ -67,6 +74,7 @@ impl CoreConfig {
directory,
hostname,
pathname,
timeout,
namespace: None,
podname: None,
uuid,
Expand Down Expand Up @@ -292,6 +300,14 @@ pub fn try_get_matches() -> clap::Result<ArgMatches> {
.takes_value(true)
.help("Hostname (same as nodename returned by uname(2))"),
)
.arg(
Arg::new("timeout")
.short('T')
.long("timeout")
.required(false)
.takes_value(true)
.help("Timeout in seconds to wait for processing of the Coredump"),
)
.arg(
Arg::new("test-threads")
.long("test-threads")
Expand Down
22 changes: 21 additions & 1 deletion core-dump-composer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,34 @@ use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::process;
use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;
use zip::write::FileOptions;
use zip::ZipWriter;

mod config;
mod logging;

fn main() -> Result<(), anyhow::Error> {
let mut cc = config::CoreConfig::new()?;
let (send, recv) = channel();
let cc = config::CoreConfig::new()?;
let timeout = cc.params.timeout.clone();

thread::spawn(move || {
let result = handle(cc);
send.send(result).unwrap();
});

let result = recv.recv_timeout(Duration::from_secs(timeout));

match result {
Ok(inner_result) => inner_result,
Err(error) => panic!("Timeout: {}", error),
}
}

fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
cc.set_namespace("default".to_string());
let l_log_level = cc.log_level.clone();
let log_path = logging::init_logger(l_log_level)?;
Expand Down

0 comments on commit 3631086

Please sign in to comment.