From 52ac5d3b3efc46fb943fe91c6862286b39bc5406 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 5 Aug 2026 17:35:01 +0300 Subject: [PATCH] cli/debug: Add `hardenedBsd` detection This is conditional on the target operating system being FreeBSDs. HardenedBSD is FreeBSD but with changes. We determine which one it is, by running 'sysctl --values hardening.version'. Co-authored-by: Shawn Webb --- crates/radicle-cli/src/commands/debug.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/radicle-cli/src/commands/debug.rs b/crates/radicle-cli/src/commands/debug.rs index e70cb39d3..45b475dbe 100644 --- a/crates/radicle-cli/src/commands/debug.rs +++ b/crates/radicle-cli/src/commands/debug.rs @@ -60,6 +60,7 @@ fn debug(profile: Option<&Profile>) -> anyhow::Result<()> { arch: std::env::consts::ARCH, env, warnings: collect_warnings(profile), + hardened_bsd: hardened_bsd(), }; term::println(serde_json::to_string_pretty(&debug).unwrap()); @@ -73,6 +74,21 @@ fn os_release() -> Option> { .map(|map| map.into_iter().map(|(k, v)| (k.to_string(), v)).collect()) } +#[cfg(target_os = "freebsd")] +fn hardened_bsd() -> Option { + let mut cmd = Command::new("sysctl"); + cmd.args(["sysctl", "--values", "hardening.version"]); + cmd.output() + .ok() + .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_string()) +} + +#[cfg(not(target_os = "freebsd"))] +#[inline] +const fn hardened_bsd() -> Option { + None +} + #[derive(Debug, Serialize)] #[allow(dead_code)] #[serde(rename_all = "camelCase")] @@ -91,6 +107,8 @@ struct DebugInfo { arch: &'static str, env: BTreeMap, + hardened_bsd: Option, + #[serde(skip_serializing_if = "Vec::is_empty")] warnings: Vec, }