Skip to content

Commit 5498552

Browse files
committed
fix(memtrack): support non-x86 libc paths
1 parent e954d5f commit 5498552

3 files changed

Lines changed: 16 additions & 28 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/memtrack/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static_assertions = "1.1"
3232
itertools = { workspace = true }
3333
paste = "1.0"
3434
libbpf-rs = { version = "0.25.0", features = ["vendored"], optional = true }
35+
glob = "0.3.3"
3536

3637
[build-dependencies]
3738
libbpf-cargo = { version = "0.25.0", optional = true }

crates/memtrack/src/libc.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,22 @@
22
pub fn find_libc_paths() -> anyhow::Result<Vec<std::path::PathBuf>> {
33
use itertools::Itertools;
44

5-
let mut paths = vec![
6-
"/lib/x86_64-linux-gnu/libc.so.6".into(),
7-
"/usr/lib/x86_64-linux-gnu/libc.so.6".into(),
8-
"/lib64/libc.so.6".into(),
9-
"/usr/lib64/libc.so.6".into(),
5+
let patterns = [
6+
// Debian, Ubuntu: Standard Linux multiarch paths
7+
"/lib/*-linux-gnu/libc.so.6",
8+
"/usr/lib/*-linux-gnu/libc.so.6",
9+
// RHEL, Fedora, CentOS, Arch:
10+
"/lib*/libc.so.6",
11+
"/usr/lib*/libc.so.6",
12+
// NixOS: find all glibc versions in the Nix store
13+
"/nix/store/*glibc*/lib/libc.so.6",
1014
];
1115

12-
// On NixOS, try to find all glibc versions in the Nix store
13-
if let Ok(entries) = std::fs::read_dir("/nix/store") {
14-
let nix_paths: Vec<_> = entries
15-
.filter_map(|entry| {
16-
let Ok(entry) = entry else { return None };
17-
18-
let path = entry.path();
19-
let file_name = path.file_name()?;
20-
let name = file_name.to_string_lossy();
21-
22-
// Look for glibc directories
23-
if name.contains("glibc") && !name.contains("locales") && !name.contains("iconv") {
24-
return Some(path.join("lib").join("libc.so.6"));
25-
}
26-
None
27-
})
28-
.collect();
29-
30-
paths.extend(nix_paths);
31-
}
32-
33-
let existing_paths = paths
34-
.into_iter()
16+
let existing_paths = patterns
17+
.iter()
18+
.flat_map(|pattern| glob::glob(pattern).ok())
19+
.flatten()
20+
.filter_map(|p| p.ok())
3521
.filter_map(|p| p.canonicalize().ok())
3622
.filter(|path| {
3723
let Ok(metadata) = std::fs::metadata(path) else {

0 commit comments

Comments
 (0)