This commit is contained in:
Mateusz Gruszczyński committed 2026-10-10 11:35:04 +02:00
1 parent f3dd34dae4
commit f213d853e2
28 files changed
+5368 -4692

No files matched your search

+33
View File
@@ -1,3 +1,33 @@
// Reuse sysinfo's native OS APIs on Linux, BSD, macOS and Windows. The
// diagnostics endpoint must never spawn system commands or parse platform files.
// Host identification is cached because it changes only after a reboot.
fn valid_host_text(value: String) -> Option<String> {
let value = value.trim();
(!value.is_empty() && value.len() <= 128 && !value.chars().any(char::is_control))
.then(|| value.to_owned())
}
fn os_release() -> Option<&'static str> {
static VALUE: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
VALUE.get_or_init(|| {
sysinfo::System::long_os_version()
.or_else(|| {
let name = sysinfo::System::name()?;
Some(match sysinfo::System::os_version() {
Some(version) if !version.is_empty() => format!("{name} {version}"),
_ => name,
})
})
.and_then(valid_host_text)
}).as_deref()
}
fn kernel_release() -> Option<&'static str> {
static VALUE: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();
VALUE.get_or_init(|| sysinfo::System::kernel_version().and_then(valid_host_text))
.as_deref()
}
fn status_payload(state: &App) -> Value {
let snapshot = state.config.load_full();
let listeners = json!({
@@ -180,6 +210,9 @@ fn status_payload(state: &App) -> Value {
});
payload["runtime"] = json!({
"platform": system.platform,
"operating_system": os_release(),
"kernel_version": kernel_release(),
"architecture": std::env::consts::ARCH,
"statistics_source": system.source,
"data_directory": state.policy.data_dir.as_ref().map(|path| path.display().to_string()),
"database_path": state.policy.data_dir.as_ref().map(|path| path.join("config.sqlite3").display().to_string()),