try multiple time to get X11 env
This commit is contained in:
parent
369a9e0805
commit
c844d99ff1
@ -164,7 +164,7 @@ pub fn start_os_service() {
|
|||||||
uid = tmp;
|
uid = tmp;
|
||||||
log::info!("uid of seat0: {}", uid);
|
log::info!("uid of seat0: {}", uid);
|
||||||
let gdm = format!("/run/user/{}/gdm/Xauthority", 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() {
|
if auth.is_empty() {
|
||||||
auth = if std::path::Path::new(&gdm).exists() {
|
auth = if std::path::Path::new(&gdm).exists() {
|
||||||
gdm
|
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 {
|
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);
|
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);
|
log::debug!("Run: {}", &cmd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user