Skip to content

Commit 844dada

Browse files
BiomeOS Developercursoragent
andcommitted
DH-1: add BIOMEOS_SOCKET_DIR to announce, socket, and deployment paths
Fixes 4 files: identity.rs (primal_announce), socket.rs (capability discovery), platform/mod.rs (get_runtime_dir), deployment.rs (zero config). All now check BIOMEOS_SOCKET_DIR before XDG_RUNTIME_DIR and use temp_dir() instead of literal "/tmp". Enables ProtectSystem=strict. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a91d0d0 commit 844dada

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

crates/cli/src/zero_config/deployment.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ enum SocketStatus {
204204
}
205205

206206
fn verify_capability_socket(capability: &str) -> SocketStatus {
207-
let runtime_dir = std::env::var(toadstool_common::interned_strings::socket_env::XDG_RUNTIME_DIR).unwrap_or_else(|_| "/tmp".into());
207+
let runtime_dir = std::env::var(toadstool_common::interned_strings::socket_env::BIOMEOS_SOCKET_DIR)
208+
.or_else(|_| std::env::var(toadstool_common::interned_strings::socket_env::XDG_RUNTIME_DIR))
209+
.unwrap_or_else(|_| std::env::temp_dir().to_string_lossy().into_owned());
208210
let socket_path = std::path::PathBuf::from(&runtime_dir)
209211
.join("biomeos")
210212
.join(format!("{capability}.sock"));

crates/core/common/src/primal_integration/socket.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ use crate::interned_strings::socket_env;
1313
///
1414
/// Discovery order:
1515
/// 1. `{CAPABILITY}_SOCKET` environment variable (e.g., `SECURITY_SOCKET`)
16-
/// 2. XDG runtime directory: `$XDG_RUNTIME_DIR/{capability}.sock` (or `/tmp` fallback)
16+
/// 2. `$BIOMEOS_SOCKET_DIR/{capability}.sock`
17+
/// 3. `$XDG_RUNTIME_DIR/{capability}.sock`
18+
/// 4. `{temp_dir}/{capability}.sock` (fallback)
1719
#[must_use]
1820
pub fn discover_service_socket_by_capability(capability: &str) -> Option<String> {
1921
let env_key = format!("{}_SOCKET", capability.to_uppercase().replace('-', "_"));
2022
std::env::var(&env_key).ok().or_else(|| {
21-
let runtime_dir =
22-
std::env::var(socket_env::XDG_RUNTIME_DIR).unwrap_or_else(|_| "/tmp".to_string());
23+
let runtime_dir = std::env::var(socket_env::BIOMEOS_SOCKET_DIR)
24+
.or_else(|_| std::env::var(socket_env::XDG_RUNTIME_DIR))
25+
.unwrap_or_else(|_| std::env::temp_dir().to_string_lossy().into_owned());
2326
let socket_path = format!("{runtime_dir}/{capability}.sock");
2427
if std::path::Path::new(&socket_path).exists() {
2528
Some(socket_path)

crates/core/toadstool/src/ipc/platform/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ fn is_android() -> bool {
177177
/// 1. `XDG_RUNTIME_DIR` (standard)
178178
/// 2. `/run/user/{uid}` via pure-Rust UID detection
179179
/// 3. `BIOMEOS_RUNTIME_DIR` env override
180-
/// 4. `/tmp/biomeos-runtime` (last resort)
180+
/// 4. `{temp_dir}/biomeos-runtime` (last resort)
181181
fn get_runtime_dir() -> String {
182182
if let Ok(dir) = std::env::var(socket_env::XDG_RUNTIME_DIR) {
183183
return dir;
184184
}
185185
if let Ok(uid) = toadstool_common::uid_detector::get_user_id() {
186186
return format!("/run/user/{uid}");
187187
}
188-
std::env::var(socket_env::BIOMEOS_RUNTIME_DIR).unwrap_or_else(|_| "/tmp/biomeos-runtime".to_string())
188+
std::env::var(socket_env::BIOMEOS_RUNTIME_DIR)
189+
.unwrap_or_else(|_| std::env::temp_dir().join("biomeos-runtime").to_string_lossy().into_owned())
189190
}
190191

191192
// ============================================================================

crates/server/src/pure_jsonrpc/handler/core/identity.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,14 @@ pub(crate) async fn primal_announce(
212212

213213
let methods = all_callable_methods(semantic_registry);
214214
let socket_name = format!("{}.sock", toadstool_common::constants::CAPABILITY_DOMAIN);
215-
let socket = std::env::var(socket_env::XDG_RUNTIME_DIR).map_or_else(
216-
|_| format!("/tmp/biomeos/{socket_name}"),
217-
|d| format!("{d}/biomeos/{socket_name}"),
218-
);
215+
let socket = if let Ok(dir) = std::env::var(socket_env::BIOMEOS_SOCKET_DIR) {
216+
format!("{dir}/{socket_name}")
217+
} else {
218+
std::env::var(socket_env::XDG_RUNTIME_DIR).map_or_else(
219+
|_| std::env::temp_dir().join("biomeos").join(&socket_name).to_string_lossy().into_owned(),
220+
|d| format!("{d}/biomeos/{socket_name}"),
221+
)
222+
};
219223

220224
Ok(serde_json::json!({
221225
"primal": PRIMAL_NAME,

0 commit comments

Comments
 (0)