Skip to content

Commit

Permalink
try multiple time to get X11 env
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed Jun 8, 2021
1 parent 369a9e0 commit c844d99
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn start_os_service() {
uid = tmp;
log::info!("uid of seat0: {}", uid);
let gdm = format!("/run/user/{}/gdm/Xauthority", uid);
let mut auth = get_env("XAUTHORITY", &uid);
let mut auth = get_env_tries("XAUTHORITY", &uid, 10);
if auth.is_empty() {
auth = if std::path::Path::new(&gdm).exists() {
gdm
Expand Down Expand Up @@ -502,6 +502,17 @@ fn run_cmds(cmds: String) -> ResultType<Option<String>> {
}
}

fn get_env_tries(name: &str, uid: &str, n: usize) -> String {
for _ in 0..n {
let x = get_env(name, uid);
if !x.is_empty() {
return x;
}
std::thread::sleep(std::time::Duration::from_millis(300));
}
"".to_owned()
}

fn get_env(name: &str, uid: &str) -> String {
let cmd = format!("ps -u {} -o pid= | xargs -I__ cat /proc/__/environ 2>/dev/null | tr '\\0' '\\n' | grep -m1 '^{}=' | sed 's/{}=//g'", uid, name, name);
log::debug!("Run: {}", &cmd);
Expand Down

0 comments on commit c844d99

Please sign in to comment.