fix: detect and enable logind functionality at runtime
Downstream distributions have optional logind, but the logind feature must be defined at compile time. If cosmic-greeter is compiled with logind support it fails to run on a host that's not running logind. Detect whether logind is present at runtime, enabling the use of the same binaries regardless of whether logind is installed or not.
This commit is contained in:
parent
d39915ae23
commit
f64e2d8fab
3 changed files with 71 additions and 40 deletions
|
|
@ -13,6 +13,27 @@ use zbus::Connection;
|
|||
use crate::common;
|
||||
use crate::locker::Message;
|
||||
|
||||
/// Checks whether logind (either elogind or systemd-logind) is reachable on the system bus.
|
||||
pub fn is_available() -> bool {
|
||||
fn ping() -> zbus::Result<()> {
|
||||
let connection = zbus::blocking::Connection::system()?;
|
||||
connection.call_method(
|
||||
Some("org.freedesktop.login1"),
|
||||
"/org/freedesktop/login1",
|
||||
Some("org.freedesktop.DBus.Peer"),
|
||||
"Ping",
|
||||
&(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
if let Err(err) = ping() {
|
||||
tracing::info!("logind not available: {}", err);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn power_off() -> zbus::Result<()> {
|
||||
let connection = Connection::system().await?;
|
||||
let manager = ManagerProxy::new(&connection).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue