Skip to content

Commit 2db8126

Browse files
committed
fix(vmm): use XDG_RUNTIME_DIR for discovery files
Use $XDG_RUNTIME_DIR/dstack-vmm instead of /run/dstack-vmm so that no root permissions are needed. Falls back to /run/dstack-vmm when XDG_RUNTIME_DIR is not set.
1 parent d46ba28 commit 2db8126

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

vmm/src/discovery.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ use std::path::{Path, PathBuf};
1313
use tracing::{info, warn};
1414
use uuid::Uuid;
1515

16-
/// Well-known directory where VMM instances register themselves.
17-
const DISCOVERY_DIR: &str = "/run/dstack-vmm";
16+
/// Returns the discovery directory path.
17+
/// Uses $XDG_RUNTIME_DIR/dstack-vmm if set, otherwise falls back to /run/dstack-vmm.
18+
fn discovery_dir() -> PathBuf {
19+
if let Ok(xdg) = std::env::var("XDG_RUNTIME_DIR") {
20+
PathBuf::from(xdg).join("dstack-vmm")
21+
} else {
22+
PathBuf::from("/run/dstack-vmm")
23+
}
24+
}
1825

1926
#[derive(Debug, Clone, Serialize, Deserialize)]
2027
pub struct VmmInstanceInfo {
@@ -57,8 +64,8 @@ impl DiscoveryRegistration {
5764
node_name: &str,
5865
version: &str,
5966
) -> Result<Self> {
60-
let dir = Path::new(DISCOVERY_DIR);
61-
fs_err::create_dir_all(dir).context("failed to create discovery directory")?;
67+
let dir = discovery_dir();
68+
fs_err::create_dir_all(&dir).context("failed to create discovery directory")?;
6269

6370
let id = Uuid::new_v4().to_string();
6471
let path = dir.join(format!("{id}.json"));
@@ -104,7 +111,7 @@ impl Drop for DiscoveryRegistration {
104111

105112
/// Clean up stale discovery files from dead processes.
106113
pub fn cleanup_stale_registrations() {
107-
let dir = Path::new(DISCOVERY_DIR);
114+
let dir = discovery_dir();
108115
let entries = match std::fs::read_dir(dir) {
109116
Ok(e) => e,
110117
Err(_) => return,

vmm/src/vmm-cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
DEFAULT_KMS_WHITELIST_PATH = os.path.expanduser("~/.dstack-vmm/kms-whitelist.json")
3636

3737
# VMM discovery directory
38-
DISCOVERY_DIR = "/run/dstack-vmm"
38+
DISCOVERY_DIR = os.path.join(os.environ.get("XDG_RUNTIME_DIR", "/run"), "dstack-vmm")
3939

4040

4141
def load_config() -> Dict[str, Any]:

0 commit comments

Comments
 (0)