Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/blocks/service_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ trait Driver {

struct SystemdDriver {
proxy: UnitProxy<'static>,
service_proxy: ServiceProxy<'static>,
active_state_changed: PropertyStream<'static, String>,
}

Expand Down Expand Up @@ -141,27 +142,49 @@ impl SystemdDriver {
let path = format!("/org/freedesktop/systemd1/unit/{encoded_service}");

let proxy = UnitProxy::builder(&dbus_conn)
.path(path)
.path(path.clone())
.error("Could not set path")?
.build()
.await
.error("Failed to create UnitProxy")?;

let service_proxy = ServiceProxy::builder(&dbus_conn)
.path(path)
.error("Could not set path")?
.build()
.await
.error("Failed to create ServiceProxy")?;

Ok(Self {
active_state_changed: proxy.receive_active_state_changed().await,
proxy,
service_proxy,
})
}
}

#[async_trait]
impl Driver for SystemdDriver {
async fn is_active(&self) -> Result<bool> {
self.proxy
let active_state = self
.proxy
.active_state()
.await
.error("Could not get active_state")
.map(|state| state == "active")
.error("Could not get active_state")?;

Ok(match &*active_state {
"active" => true,
"activating" => {
let service_type = self
.service_proxy
.type_()
.await
.error("Could not get service type")?;
Comment on lines +178 to +182
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this property every time in case the underlying service changes.


service_type == "oneshot"
}
_ => false,
})
}

async fn wait_for_change(&mut self) -> Result<()> {
Expand All @@ -178,3 +201,12 @@ trait Unit {
#[zbus(property)]
fn active_state(&self) -> zbus::Result<String>;
}

#[zbus::proxy(
interface = "org.freedesktop.systemd1.Service",
default_service = "org.freedesktop.systemd1"
)]
trait Service {
#[zbus(property, name = "Type")]
fn type_(&self) -> zbus::Result<String>;
}