Browse Source

Replace `Arc` with `&'static`

Tamir Duberstein 5 months ago
parent
commit
e992c280cb
2 changed files with 7 additions and 9 deletions
  1. 5 7
      aya/src/programs/uprobe.rs
  2. 2 2
      xtask/public-api/aya.txt

+ 5 - 7
aya/src/programs/uprobe.rs

@@ -8,7 +8,7 @@ use std::{
     mem,
     os::{fd::AsFd as _, raw::c_char, unix::ffi::OsStrExt},
     path::{Path, PathBuf},
-    sync::{Arc, LazyLock},
+    sync::LazyLock,
 };
 
 use libc::pid_t;
@@ -29,8 +29,8 @@ use crate::{
 
 const LD_SO_CACHE_FILE: &str = "/etc/ld.so.cache";
 
-static LD_SO_CACHE: LazyLock<Result<LdSoCache, Arc<io::Error>>> =
-    LazyLock::new(|| LdSoCache::load(LD_SO_CACHE_FILE).map_err(Arc::new));
+static LD_SO_CACHE: LazyLock<Result<LdSoCache, io::Error>> =
+    LazyLock::new(|| LdSoCache::load(LD_SO_CACHE_FILE));
 const LD_SO_CACHE_HEADER_OLD: &str = "ld.so-1.7.0\0";
 const LD_SO_CACHE_HEADER_NEW: &str = "glibc-ld.so.cache1.1";
 
@@ -140,9 +140,7 @@ fn resolve_attach_path(target: &Path, pid: Option<pid_t>) -> Result<Cow<'_, Path
     .or_else(|| {
         LD_SO_CACHE
             .as_ref()
-            .map_err(|error| UProbeError::InvalidLdSoCache {
-                io_error: error.clone(),
-            })
+            .map_err(|io_error| UProbeError::InvalidLdSoCache { io_error })
             .map(|cache| cache.resolve(target).map(Cow::Borrowed))
             .transpose()
     })
@@ -215,7 +213,7 @@ pub enum UProbeError {
     InvalidLdSoCache {
         /// the original [`io::Error`]
         #[source]
-        io_error: Arc<io::Error>,
+        io_error: &'static io::Error,
     },
 
     /// The target program could not be found.

+ 2 - 2
xtask/public-api/aya.txt

@@ -6067,7 +6067,7 @@ pub aya::programs::uprobe::UProbeError::FileError
 pub aya::programs::uprobe::UProbeError::FileError::filename: std::path::PathBuf
 pub aya::programs::uprobe::UProbeError::FileError::io_error: std::io::error::Error
 pub aya::programs::uprobe::UProbeError::InvalidLdSoCache
-pub aya::programs::uprobe::UProbeError::InvalidLdSoCache::io_error: alloc::sync::Arc<std::io::error::Error>
+pub aya::programs::uprobe::UProbeError::InvalidLdSoCache::io_error: &'static std::io::error::Error
 pub aya::programs::uprobe::UProbeError::InvalidTarget
 pub aya::programs::uprobe::UProbeError::InvalidTarget::path: std::path::PathBuf
 pub aya::programs::uprobe::UProbeError::SymbolError
@@ -7343,7 +7343,7 @@ pub aya::programs::UProbeError::FileError
 pub aya::programs::UProbeError::FileError::filename: std::path::PathBuf
 pub aya::programs::UProbeError::FileError::io_error: std::io::error::Error
 pub aya::programs::UProbeError::InvalidLdSoCache
-pub aya::programs::UProbeError::InvalidLdSoCache::io_error: alloc::sync::Arc<std::io::error::Error>
+pub aya::programs::UProbeError::InvalidLdSoCache::io_error: &'static std::io::error::Error
 pub aya::programs::UProbeError::InvalidTarget
 pub aya::programs::UProbeError::InvalidTarget::path: std::path::PathBuf
 pub aya::programs::UProbeError::SymbolError