Forward audio latency environment to Linux user server (#16597)

* Forward audio latency environment to Linux user server

Preserve PULSE_LATENCY_MSEC and PIPEWIRE_LATENCY when the root service spawns the per-user RustDesk server.

The systemd service defines these variables, but they were not included in the explicit environment passed to run_as_user(), causing the user server and connection manager to fall back to higher audio latency.

Forward the existing values without changing their defaults.

* Add regression test for Linux audio latency forwarding

---------

Co-authored-by: chg <chg@vis-ag.ch>
This commit is contained in:
Chris21xandchg authored and GitHub committed 2026-10-20 17:13:11 +08:00
1 parent 1042a26deb
commit 0cbeb04730
1 file changed
+40
+40
View File
@@ -891,6 +891,43 @@ fn get_all_term_values(uid: &str) -> Vec<String> {
terms
}
fn append_audio_latency_envs(
envs: &mut Vec<(&'static str, String)>,
get_var: impl Fn(&str) -> Option<String>,
) {
for key in ["PULSE_LATENCY_MSEC", "PIPEWIRE_LATENCY"] {
if let Some(value) = get_var(key).filter(|value| !value.is_empty()) {
envs.push((key, value));
}
}
}
#[cfg(test)]
mod audio_latency_env_tests {
use super::append_audio_latency_envs;
#[test]
fn forwards_configured_values_without_creating_defaults() {
let mut envs = Vec::new();
append_audio_latency_envs(&mut envs, |key| match key {
"PULSE_LATENCY_MSEC" => Some("60".to_owned()),
"PIPEWIRE_LATENCY" => Some("1024/48000".to_owned()),
_ => None,
});
assert_eq!(
envs,
vec![
("PULSE_LATENCY_MSEC", "60".to_owned()),
("PIPEWIRE_LATENCY", "1024/48000".to_owned()),
]
);
envs.clear();
append_audio_latency_envs(&mut envs, |_| None);
assert!(envs.is_empty());
}
}
#[inline]
fn try_start_server_(desktop: Option<&Desktop>) -> ResultType<Option<Child>> {
match desktop {
@@ -921,6 +958,9 @@ fn try_start_server_(desktop: Option<&Desktop>) -> ResultType<Option<Child>> {
));
}
}
append_audio_latency_envs(&mut envs, |key| std::env::var(key).ok());
envs.push((
"TERM",
get_cur_term(&desktop.uid).unwrap_or_else(|| suggest_best_term()),