Replace `lazy_static` with `std::sync::LazyLock`

pull/1043/head
Tamir Duberstein 4 months ago
parent 0f163633e3
commit 2b299d4fba

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

@ -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"] }

@ -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<T: Pod, const N: usize> 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<Features> = LazyLock::new(detect_features);
fn detect_features() -> Features {
let btf = if is_btf_supported() {

@ -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, Arc<io::Error>> =
LdSoCache::load(LD_SO_CACHE_FILE).map_err(Arc::new);
}
static LD_SO_CACHE: LazyLock<Result<LdSoCache, Arc<io::Error>>> =
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";

@ -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<T: Link + From<FdLink>>(
/// 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 = [
static TRACE_FS: LazyLock<Option<&'static Path>> = LazyLock::new(|| {
[
Path::new("/sys/kernel/tracing"),
Path::new("/sys/kernel/debug/tracing"),
];
for mount in known_mounts {
]
.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.
if mount.exists() && mount.read_dir().ok()?.next().is_some() {
return Some(mount);
}
}
None
};
mount.exists()
&& match mount.read_dir() {
Ok(mut entries) => entries.next().is_some(),
Err(io::Error { .. }) => false,
}
})
});
TRACE_FS
.as_deref()

Loading…
Cancel
Save