From 183d1a91c10b1f24b24afdc6449d9fa048d5e36c Mon Sep 17 00:00:00 2001 From: tiann Date: Wed, 12 Apr 2023 13:17:13 +0800 Subject: [PATCH] ksud: add error context to log --- userspace/ksud/src/event.rs | 4 ++-- userspace/ksud/src/mount.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/userspace/ksud/src/event.rs b/userspace/ksud/src/event.rs index f5081348..156e9477 100644 --- a/userspace/ksud/src/event.rs +++ b/userspace/ksud/src/event.rs @@ -93,13 +93,13 @@ pub fn mount_systemlessly(module_dir: &str) -> Result<()> { // mount /system first if let Err(e) = mount_partition("system", &mut system_lowerdir) { - warn!("mount system failed: {e}"); + warn!("mount system failed: {:#}", e); } // mount other partitions for (k, mut v) in partition_lowerdir { if let Err(e) = mount_partition(&k, &mut v) { - warn!("mount {k} failed: {e}"); + warn!("mount {k} failed: {:#}", e); } } diff --git a/userspace/ksud/src/mount.rs b/userspace/ksud/src/mount.rs index 75a4b3a9..7fbf4ba4 100644 --- a/userspace/ksud/src/mount.rs +++ b/userspace/ksud/src/mount.rs @@ -1,4 +1,4 @@ -use anyhow::{Ok, Result}; +use anyhow::{bail, Ok, Result}; #[cfg(any(target_os = "linux", target_os = "android"))] use anyhow::Context; @@ -282,16 +282,21 @@ impl StockMount { let path = rootdir.join(dest.strip_prefix("/")?); log::info!("rootdir: {}, path: {}", rootdir.display(), path.display()); if dest.is_dir() { - utils::ensure_dir_exists(&path)?; + utils::ensure_dir_exists(&path) + .with_context(|| format!("Failed to create dir: {}", path.display(),))?; } else if dest.is_file() { - utils::ensure_file_exists(&path)?; + utils::ensure_file_exists(&path) + .with_context(|| format!("Failed to create file: {}", path.display(),))?; } else { - log::warn!("unknown file type: {:?}", dest); + bail!("unknown file type: {:?}", dest) } log::info!("bind stock mount: {} -> {}", dest.display(), path.display()); Mount::builder() .flags(MountFlags::BIND) - .mount(dest, &path)?; + .mount(dest, &path) + .with_context(|| { + format!("Failed to mount: {} -> {}", dest.display(), path.display()) + })?; ms.push((m.clone(), path)); }