From a830922dea02a405b0516e4ece733d2e9a378c76 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Mon, 14 Jun 2021 13:16:20 +0800 Subject: [PATCH] https://github.com/rustdesk/rustdesk/issues/73 --- src/platform/linux.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/platform/linux.rs b/src/platform/linux.rs index c563fbec0..9fbddb826 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -326,13 +326,32 @@ fn get_value_of_seat0(i: usize) -> String { } } } + + // some case, there is no seat0 https://github.com/rustdesk/rustdesk/issues/73 + if let Ok(output) = std::process::Command::new("loginctl").output() { + for line in String::from_utf8_lossy(&output.stdout).lines() { + if let Some(sid) = line.split_whitespace().nth(0) { + let d = get_display_server_of_session(sid); + if is_active(sid) && d != "tty" { + if let Some(uid) = line.split_whitespace().nth(i) { + return uid.to_owned(); + } + } + } + } + } + return "".to_owned(); } pub fn get_display_server() -> String { let session = get_value_of_seat0(0); + get_display_server_of_session(&session) +} + +fn get_display_server_of_session(session: &str) -> String { if let Ok(output) = std::process::Command::new("loginctl") - .args(vec!["show-session", "-p", "Type", &session]) + .args(vec!["show-session", "-p", "Type", session]) .output() { String::from_utf8_lossy(&output.stdout)