Skip to content

Commit 2d797c5

Browse files
Stebalienbim9262
authored andcommitted
Treat oneshot systemd services as "active" when "activating"
Oneshot systemd services transition directly from activating to dead/inactive and never show up as "active". This change treats these services as "active" when "activating" because that's likely what the user wants. Otherwise, backup tasks, etc. never show up as active services in i3status-rs.
1 parent 43ba470 commit 2d797c5

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/blocks/service_status.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ trait Driver {
108108

109109
struct SystemdDriver {
110110
proxy: UnitProxy<'static>,
111+
service_proxy: ServiceProxy<'static>,
111112
active_state_changed: PropertyStream<'static, String>,
112113
}
113114

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

143144
let proxy = UnitProxy::builder(&dbus_conn)
144-
.path(path)
145+
.path(path.clone())
145146
.error("Could not set path")?
146147
.build()
147148
.await
148149
.error("Failed to create UnitProxy")?;
149150

151+
let service_proxy = ServiceProxy::builder(&dbus_conn)
152+
.path(path)
153+
.error("Could not set path")?
154+
.build()
155+
.await
156+
.error("Failed to create ServiceProxy")?;
157+
150158
Ok(Self {
151159
active_state_changed: proxy.receive_active_state_changed().await,
152160
proxy,
161+
service_proxy,
153162
})
154163
}
155164
}
156165

157166
#[async_trait]
158167
impl Driver for SystemdDriver {
159168
async fn is_active(&self) -> Result<bool> {
160-
self.proxy
169+
let active_state = self
170+
.proxy
161171
.active_state()
162172
.await
163-
.error("Could not get active_state")
164-
.map(|state| state == "active")
173+
.error("Could not get active_state")?;
174+
175+
Ok(match &*active_state {
176+
"active" => true,
177+
"activating" => {
178+
let service_type = self
179+
.service_proxy
180+
.type_()
181+
.await
182+
.error("Could not get service type")?;
183+
184+
service_type == "oneshot"
185+
}
186+
_ => false,
187+
})
165188
}
166189

167190
async fn wait_for_change(&mut self) -> Result<()> {
@@ -178,3 +201,12 @@ trait Unit {
178201
#[zbus(property)]
179202
fn active_state(&self) -> zbus::Result<String>;
180203
}
204+
205+
#[zbus::proxy(
206+
interface = "org.freedesktop.systemd1.Service",
207+
default_service = "org.freedesktop.systemd1"
208+
)]
209+
trait Service {
210+
#[zbus(property, name = "Type")]
211+
fn type_(&self) -> zbus::Result<String>;
212+
}

0 commit comments

Comments
 (0)