mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-07 21:11:05 +03:00
Prefer active X11 session display (#15933)
* Prefer active X11 session display * Update linux.rs * fix(linux): keep the logind display only when it is a local one `get_display_from_session` returns the value pam_systemd was handed at session creation, and logind never updates it afterwards. That value is not always a usable local display: it can be qualified with this host (`myhost:0`), name an X forwarding endpoint (`localhost:10.0`), or be a bare `:`. Taking it unconditionally is worse than taking nothing, because a non-empty `self.display` suppresses every fallback below it, `get_display_by_user` and the `:0` default alike. The stripping at the end of `get_display_x11` does not save the last two cases either: it leaves `:` as is and turns `localhost:10.0` into a local looking `:10.0`, either of which is then exported as DISPLAY and leaves the session unreachable, where before this PR the host got a working `:0`. Strip this host so `myhost:0` is still accepted as `:0`, leave `localhost` in place, and require a display number after the colon. Anything else falls through to the existing chain. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKJxvTT6NQDEcnkWBx5bLA * docs(agents): prefer a little duplication over a restructure The "Be minimally invasive" rules already ask for purely additive diffs, but not in the case where the addition would otherwise reshape an existing function so the two can share code. Repeating a few lines is the better diff there. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKJxvTT6NQDEcnkWBx5bLA --------- Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2058,6 +2058,21 @@ mod desktop {
|
||||
sleep_millis(300);
|
||||
}
|
||||
|
||||
if self.display.is_empty() {
|
||||
// logind stores the value pam_systemd was handed at session creation, which is not
|
||||
// necessarily a local display: it can be qualified with this host (`myhost:0`) or
|
||||
// name an X forwarding endpoint (`localhost:10.0`), and some setups record a bare
|
||||
// `:`. Strip this host, then require a display number. `localhost` is deliberately
|
||||
// left in place: a non-empty display here suppresses every fallback below, both
|
||||
// `get_display_by_user` and the `:0` default, so anything not local must not pass.
|
||||
let display = Self::get_display_from_session(&self.sid)
|
||||
.replace(&hbb_common::whoami::hostname(), "");
|
||||
if display.strip_prefix(':').map_or(false, |number| {
|
||||
number.starts_with(|c: char| c.is_ascii_digit())
|
||||
}) {
|
||||
self.display = display;
|
||||
}
|
||||
}
|
||||
if self.display.is_empty() {
|
||||
self.display = Self::get_display_by_user(&self.username);
|
||||
}
|
||||
@@ -2070,6 +2085,34 @@ mod desktop {
|
||||
.replace("localhost", "");
|
||||
}
|
||||
|
||||
fn get_display_from_session(session: &str) -> String {
|
||||
if session.is_empty() {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
match Command::new(CMD_LOGINCTL.as_str())
|
||||
.args(["show-session", "-p", "Display", session])
|
||||
.output()
|
||||
{
|
||||
Ok(output) if output.status.success() => String::from_utf8_lossy(&output.stdout)
|
||||
.trim()
|
||||
.strip_prefix("Display=")
|
||||
.unwrap_or_default()
|
||||
.to_owned(),
|
||||
Ok(output) => {
|
||||
log::debug!(
|
||||
"Failed to get display for session {session}: {}",
|
||||
output.status
|
||||
);
|
||||
String::new()
|
||||
}
|
||||
Err(err) => {
|
||||
log::debug!("Failed to get display for session {session}: {err}");
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_home(&mut self) {
|
||||
self.home = "".to_string();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user