Update linux.rs

Fix for #921 
in mx linux, when started with non-systemd init, loginctl returns null string to stdout (and an error message to stderr).  this patch will use XDG_SESSION_TYPE and XDG_SESSION_ID environment variables if the loginctl code fails to determine these.
This commit is contained in:
sirtemporary 2022-07-30 15:03:49 -04:00 committed by GitHub
parent 1a4f0507a2
commit f9d0974fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,10 @@ fn get_display_server_of_session(session: &str) -> String {
display_server display_server
} }
} else { } else {
// loginctl has not given the expected output. try something else.
if let OK(sestype) = std::env::var("XDG_SESSION_TYPE") {
return sestype.to_owned();
}
// If the session is not a tty, then just return the type as usual // If the session is not a tty, then just return the type as usual
display_server display_server
} }
@ -80,6 +84,11 @@ pub fn get_value_of_seat0(i: usize) -> String {
} }
} }
// loginctl has not given the expected output. try something else.
if let Ok(sid) = std::env::var("XDG_SESSION_ID") { // could also execute "cat /proc/self/sessionid"
return sid.to_owned();
}
return "".to_owned(); return "".to_owned();
} }