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 <shawn.webb@hardenedbsd.org>
This commit is contained in:
Lars Wirzenius
2026-08-12 16:42:48 +02:00
committed by Lorenz Leutgeb
co-authored by Shawn Webb
parent 9f05038234
commit 52ac5d3b3e
+18
View File
@@ -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<HashMap<String, String>> {
.map(|map| map.into_iter().map(|(k, v)| (k.to_string(), v)).collect())
}
#[cfg(target_os = "freebsd")]
fn hardened_bsd() -> Option<String> {
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<String> {
None
}
#[derive(Debug, Serialize)]
#[allow(dead_code)]
#[serde(rename_all = "camelCase")]
@@ -91,6 +107,8 @@ struct DebugInfo {
arch: &'static str,
env: BTreeMap<String, String>,
hardened_bsd: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
warnings: Vec<String>,
}