Skip to content

Commit

Permalink
rustjail: Add anyhow context for D-Bus connections
Browse files Browse the repository at this point in the history
In cases where the D-Bus connection fails, add a little additional context about
the origin of the error.

Fixes: 6561

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
Suggested-by: Archana Shinde <archana.m.shinde@intel.com>
Spell-checked-by: Greg Kurz <gkurz@redhat.com>
  • Loading branch information
c3d committed Apr 3, 2023
1 parent 7796e6c commit b661e0c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/agent/rustjail/src/cgroups/systemd/dbus_client.rs
Expand Up @@ -36,8 +36,9 @@ pub struct DBusClient {}

impl DBusClient {
fn build_proxy(&self) -> Result<SystemManager<'static>> {
let connection = zbus::blocking::Connection::system()?;
let proxy = SystemManager::new(&connection)?;
let connection =
zbus::blocking::Connection::system().context("Establishing a D-Bus connection")?;
let proxy = SystemManager::new(&connection).context("Building a D-Bus proxy manager")?;
Ok(proxy)
}
}
Expand Down Expand Up @@ -109,7 +110,9 @@ impl SystemdInterface for DBusClient {
}

fn unit_exists(&self, unit_name: &str) -> Result<bool> {
let proxy = self.build_proxy()?;
let proxy = self
.build_proxy()
.with_context(|| format!("Checking if systemd unit {} exists", unit_name))?;

Ok(proxy.get_unit(unit_name).is_ok())
}
Expand Down

0 comments on commit b661e0c

Please sign in to comment.