try multiple time to get X11 env

This commit is contained in:
rustdesk 2021-06-08 17:54:25 +08:00
parent 369a9e0805
commit c844d99ff1

View File

@ -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
@ -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);