diff --git a/Cargo.toml b/Cargo.toml index d6fbd290..1f8b4c28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,7 +72,6 @@ futures = { version = "0.3.28", default-features = false } hashbrown = { version = "0.14.3", default-features = false } indoc = { version = "2.0", default-features = false } integration-ebpf = { path = "test/integration-ebpf", default-features = false } -lazy_static = { version = "1", default-features = false } libc = { version = "0.2.105", default-features = false } log = { version = "0.4", default-features = false } netns-rs = { version = "0.1", default-features = false } diff --git a/aya/Cargo.toml b/aya/Cargo.toml index 57e80c77..5222fb5a 100644 --- a/aya/Cargo.toml +++ b/aya/Cargo.toml @@ -5,7 +5,7 @@ description = "An eBPF library with a focus on developer experience and operabil keywords = ["bpf", "ebpf", "kernel", "linux"] readme = "README.md" documentation = "https://docs.rs/aya" -rust-version = "1.66" +rust-version = "1.80.0" authors.workspace = true license.workspace = true repository.workspace = true @@ -18,7 +18,6 @@ async-io = { workspace = true, optional = true } aya-obj = { path = "../aya-obj", version = "^0.1.0", features = ["std"] } bitflags = { workspace = true } bytes = { workspace = true } -lazy_static = { workspace = true } libc = { workspace = true } log = { workspace = true } object = { workspace = true, features = ["elf", "read_core", "std", "write"] } diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index 8a189476..e9cad2b5 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -7,7 +7,7 @@ use std::{ raw::c_int, }, path::{Path, PathBuf}, - sync::Arc, + sync::{Arc, LazyLock}, }; use aya_obj::{ @@ -70,9 +70,7 @@ unsafe impl Pod for [T; N] {} pub use aya_obj::maps::{bpf_map_def, PinningType}; -lazy_static::lazy_static! { - pub(crate) static ref FEATURES: Features = detect_features(); -} +pub(crate) static FEATURES: LazyLock = LazyLock::new(detect_features); fn detect_features() -> Features { let btf = if is_btf_supported() { diff --git a/aya/src/programs/uprobe.rs b/aya/src/programs/uprobe.rs index 28d6749f..2e63e39e 100644 --- a/aya/src/programs/uprobe.rs +++ b/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, + sync::{Arc, LazyLock}, }; use libc::pid_t; @@ -29,10 +29,8 @@ use crate::{ const LD_SO_CACHE_FILE: &str = "/etc/ld.so.cache"; -lazy_static::lazy_static! { - static ref LD_SO_CACHE: Result> = - LdSoCache::load(LD_SO_CACHE_FILE).map_err(Arc::new); -} +static LD_SO_CACHE: LazyLock>> = + LazyLock::new(|| LdSoCache::load(LD_SO_CACHE_FILE).map_err(Arc::new)); 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"; diff --git a/aya/src/programs/utils.rs b/aya/src/programs/utils.rs index 0930e62b..9eabbd81 100644 --- a/aya/src/programs/utils.rs +++ b/aya/src/programs/utils.rs @@ -5,6 +5,7 @@ use std::{ io::{self, BufRead, BufReader}, os::fd::{AsFd as _, AsRawFd as _, BorrowedFd}, path::Path, + sync::LazyLock, time::{Duration, SystemTime, UNIX_EPOCH}, }; @@ -31,27 +32,26 @@ pub(crate) fn attach_raw_tracepoint>( /// Find tracefs filesystem path. pub(crate) fn find_tracefs_path() -> Result<&'static Path, ProgramError> { - lazy_static::lazy_static! { - static ref TRACE_FS: Option<&'static Path> = { - let known_mounts = [ - Path::new("/sys/kernel/tracing"), - Path::new("/sys/kernel/debug/tracing"), - ]; - - for mount in known_mounts { - // Check that the mount point exists and is not empty - // Documented here: (https://www.kernel.org/doc/Documentation/trace/ftrace.txt) - // In some cases, tracefs will only mount at /sys/kernel/debug/tracing - // but, the kernel will still create the directory /sys/kernel/tracing. - // The user may be expected to manually mount the directory in order for it to - // exist in /sys/kernel/tracing according to the documentation. - if mount.exists() && mount.read_dir().ok()?.next().is_some() { - return Some(mount); + static TRACE_FS: LazyLock> = LazyLock::new(|| { + [ + Path::new("/sys/kernel/tracing"), + Path::new("/sys/kernel/debug/tracing"), + ] + .into_iter() + .find(|&mount| { + // Check that the mount point exists and is not empty + // Documented here: (https://www.kernel.org/doc/Documentation/trace/ftrace.txt) + // In some cases, tracefs will only mount at /sys/kernel/debug/tracing + // but, the kernel will still create the directory /sys/kernel/tracing. + // The user may be expected to manually mount the directory in order for it to + // exist in /sys/kernel/tracing according to the documentation. + mount.exists() + && match mount.read_dir() { + Ok(mut entries) => entries.next().is_some(), + Err(io::Error { .. }) => false, } - } - None - }; - } + }) + }); TRACE_FS .as_deref()