Skip to content

Commit

Permalink
runtime-rs: Fix Panic Issue with 'enable-debug' Option on Cloud Hyper…
Browse files Browse the repository at this point in the history
…visor

Fixes a problem where parse_ch_log_level() fails to work correctly
when the "enable-debug" option is turned on in the configuration.toml.

Root Cause of Panic:
Parsing certain logs,
such as "[0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd0c0]"
        "cloud-hypervisor: 1.302s: <vcpu0> INFO:.."
can triggers the following panic:
{"msg":"A panic occurred at crates/hypervisor/src/ch/inner_hypervisor.rs:768: There should be a match for level\r\n"...

Fixes: #8416

Signed-off-by: briwan01 <brian.wang@arm.com>
  • Loading branch information
brianwang12 committed Nov 13, 2023
1 parent 6bad5cd commit b20c44d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,16 @@ async fn cloud_hypervisor_log_output(mut child: Child, mut shutdown: Receiver<bo
}

pub fn parse_ch_log_level(line: &str) -> &str {
let re = Regex::new(r"cloud-hypervisor: [0-9]*[.][0-9]+ms: <\w+> (?<level>\w+)").unwrap();
let level = re
.captures(line)
.expect("There should be a match for level")
.name("level")
.expect("Level should be found in record")
.as_str();
let re = Regex::new(r"cloud-hypervisor: [0-9]*[.][0-9]+.s: <\w+> (?<clh_level>\w+)").unwrap();

let mut level = "INFO";

if let Some(captures) = re.captures(line) {
if let Some(clh_level) = captures.name("clh_level") {
level = clh_level.as_str();
}
}

match level {
"TRACE" => LOG_LEVEL_TRACE,
"DEBUG" => LOG_LEVEL_DEBUG,
Expand Down

0 comments on commit b20c44d

Please sign in to comment.