Skip to content

Commit 22baf91

Browse files
committed
refactor(vmm): use nix::unistd::getuid for UID fallback in discovery
Replace /proc/self/status parsing with nix crate's getuid() for cleaner UID detection when XDG_RUNTIME_DIR is not set.
1 parent 7eebc38 commit 22baf91

2 files changed

Lines changed: 2 additions & 10 deletions

File tree

vmm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ uuid = { workspace = true, features = ["v4"] }
2323
sha2.workspace = true
2424
hex.workspace = true
2525
fs-err.workspace = true
26+
nix = { workspace = true, features = ["user"] }
2627
dirs.workspace = true
2728
which.workspace = true
2829
clap = { workspace = true, features = ["derive", "string"] }

vmm/src/discovery.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@ fn discovery_dir() -> PathBuf {
1919
if let Ok(xdg) = std::env::var("XDG_RUNTIME_DIR") {
2020
return PathBuf::from(xdg).join("dstack-vmm");
2121
}
22-
// Read real uid from /proc/self/status to avoid adding a libc dependency.
23-
let uid = std::fs::read_to_string("/proc/self/status")
24-
.ok()
25-
.and_then(|s| {
26-
s.lines()
27-
.find(|l| l.starts_with("Uid:"))
28-
.and_then(|l| l.split_whitespace().nth(1))
29-
.and_then(|v| v.parse::<u32>().ok())
30-
})
31-
.expect("failed to determine uid from /proc/self/status");
22+
let uid = nix::unistd::getuid();
3223
PathBuf::from(format!("/run/user/{uid}/dstack-vmm"))
3324
}
3425

0 commit comments

Comments
 (0)