Skip to content

Commit

Permalink
virtme-ng-init: fail gracefully when executing external commands
Browse files Browse the repository at this point in the history
Prevent crashing init when an external command cannot be executed,
instead fail gracefully logging a warning.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
  • Loading branch information
Andrea Righi committed Oct 6, 2023
1 parent 9d5ed51 commit 2b45725
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,20 @@ pub fn run_cmd(cmd: &str, args: &[&str]) {
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.ok();
log(String::from_utf8_lossy(&output.unwrap().stderr).trim_end_matches('\n'));
.output();

match output {
Ok(output) => {
if !output.stderr.is_empty() {
log(String::from_utf8_lossy(&output.stderr).trim_end_matches('\n'));
}
}
Err(_) => {
log(&format!(
"WARNING: failed to run: {} {}",
cmd,
args.join(" ")
));
}
}
}

0 comments on commit 2b45725

Please sign in to comment.