feat(linux): run systemd service as unprivileged numa user #118

Merged
razvandimescu merged 11 commits from feat/linux-drop-privileges into main 2026-04-19 03:04:54 +08:00
Showing only changes of commit e19505aa95 - Show all commits

View File

@@ -1416,7 +1416,7 @@ pub fn service_status() -> Result<(), String> {
} }
} }
#[cfg(any(target_os = "macos", target_os = "linux"))] #[cfg(target_os = "macos")]
fn replace_exe_path(service: &str) -> Result<String, String> { fn replace_exe_path(service: &str) -> Result<String, String> {
let exe_path = let exe_path =
std::env::current_exe().map_err(|e| format!("failed to get current exe: {}", e))?; std::env::current_exe().map_err(|e| format!("failed to get current exe: {}", e))?;
@@ -2050,22 +2050,25 @@ Wireless LAN adapter Wi-Fi:
} }
#[test] #[test]
#[cfg(any(target_os = "macos", target_os = "linux"))] fn install_templates_contain_exe_path_placeholder() {
fn replace_exe_path_substitutes_template() { // Both files are substituted at install time — plist via
// replace_exe_path on macOS, numa.service via inline .replace
// in install_service_linux. Catch placeholder removal early.
let plist = include_str!("../com.numa.dns.plist"); let plist = include_str!("../com.numa.dns.plist");
let unit = include_str!("../numa.service"); let unit = include_str!("../numa.service");
assert!(plist.contains("{{exe_path}}"), "plist missing placeholder"); assert!(plist.contains("{{exe_path}}"), "plist missing placeholder");
assert!( assert!(
unit.contains("{{exe_path}}"), unit.contains("{{exe_path}}"),
"unit file missing placeholder" "unit file missing placeholder"
); );
}
#[test]
#[cfg(target_os = "macos")]
fn replace_exe_path_substitutes_template() {
let plist = include_str!("../com.numa.dns.plist");
let result = replace_exe_path(plist).expect("replace_exe_path failed for plist"); let result = replace_exe_path(plist).expect("replace_exe_path failed for plist");
assert!(!result.contains("{{exe_path}}")); assert!(!result.contains("{{exe_path}}"));
let result = replace_exe_path(unit).expect("replace_exe_path failed for unit");
assert!(!result.contains("{{exe_path}}"));
} }
#[test] #[test]