From 4a6942dd3347e3a21e863ec8413a95d8b19c4461 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 19 Aug 2022 17:20:48 -0700 Subject: [PATCH] base: syslog: make platform syslog init non-fatal If we can't create a PlatformSyslog instance (for example, if /dev/log is not available on a minimal Linux system without a traditional init), warn the user and continue executing instead of failing. BUG=b:242103548 TEST=Run crosvm inside minimal VM with no init Change-Id: I4d81da396125331ef7ad335e57b37645b6546980 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3842814 Tested-by: Daniel Verkamp Commit-Queue: Daniel Verkamp Reviewed-by: Abhishek Bhardwaj Reviewed-by: Noah Gold --- base/src/syslog.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/base/src/syslog.rs b/base/src/syslog.rs index eb1839b702..f685bc9213 100644 --- a/base/src/syslog.rs +++ b/base/src/syslog.rs @@ -316,12 +316,21 @@ impl State { } if cfg.syslog { - let (mut logger, fd) = PlatformSyslog::new(cfg.proc_name, cfg.syslog_facility)?; - if let Some(fd) = fd { - descriptors.push(fd); - } - if let Some(logger) = logger.take() { - loggers.push(logger); + match PlatformSyslog::new(cfg.proc_name, cfg.syslog_facility) { + Ok((mut logger, fd)) => { + if let Some(fd) = fd { + descriptors.push(fd); + } + if let Some(logger) = logger.take() { + loggers.push(logger); + } + } + Err(e) => { + // The default log configuration used in early_init() enables syslog, so we + // don't want to terminate the program if syslog can't be initialized. Warn the + // user but continue running. + eprintln!("syslog init failed: {}", e); + } } }