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 <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
This commit is contained in:
Daniel Verkamp 2022-08-19 17:20:48 -07:00 committed by crosvm LUCI
parent eac63e6a50
commit 4a6942dd33

View file

@ -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);
}
}
}