From 7cb61d396032aa982e974c36d205aecdd43d67a9 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 3 Feb 2020 17:13:18 +0000 Subject: [PATCH] main: Don't panic (by calling .expect()) if writing to the log fails As this can happen during the running of the VMM we should be very careful not to panic() as that can lead to a thread being used by the VM disappearing. Signed-off-by: Rob Bradford --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 81254a99a..9aade380b 100755 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ impl log::Log for Logger { let now = std::time::Instant::now(); let duration = now.duration_since(self.start); - if record.file().is_some() && record.line().is_some() { + if let Err(e) = if record.file().is_some() && record.line().is_some() { writeln!( *(*(self.output.lock().unwrap())), "cloud-hypervisor: {:?}: {}:{}:{} -- {}", @@ -48,7 +48,6 @@ impl log::Log for Logger { record.line().unwrap(), record.args() ) - .expect("Failed to write to log file"); } else { writeln!( *(*(self.output.lock().unwrap())), @@ -58,7 +57,8 @@ impl log::Log for Logger { record.target(), record.args() ) - .expect("Failed to write to log file"); + } { + eprintln!("Error writing log output: {:?}", e); } } fn flush(&self) {}