Skip to content

Commit a546efa

Browse files
mmstickjackpot51
authored andcommitted
fix: wrong zbus connection used to emit system76-power profile change signals
1 parent 975a3b4 commit a546efa

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/daemon/mod.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ struct PowerDaemon {
7575
profile_errors: Vec<ProfileError>,
7676
held_profiles: Vec<(u32, &'static str, String, String)>,
7777
profile_ids: u32,
78-
connection: zbus::Connection,
79-
connections: Option<(zbus::Connection, zbus::Connection)>,
78+
connections: Option<(zbus::Connection, zbus::Connection, zbus::Connection)>,
8079
}
8180

8281
impl PowerDaemon {
83-
fn new(connection: zbus::Connection) -> anyhow::Result<Self> {
82+
fn new() -> anyhow::Result<Self> {
8483
let graphics = Graphics::new()?;
8584

8685
Ok(Self {
@@ -90,7 +89,6 @@ impl PowerDaemon {
9089
profile_errors: Vec::new(),
9190
held_profiles: Vec::new(),
9291
profile_ids: 0,
93-
connection,
9492
connections: None,
9593
})
9694
}
@@ -132,7 +130,7 @@ impl System76Power {
132130
pub async fn emit_active_profile_changed(&self) {
133131
let (upp_connection, hadess_connection, profile) = {
134132
let this = self.0.lock().await;
135-
let Some((upp, hadess)) = this.connections.clone() else { return };
133+
let Some((_, upp, hadess)) = this.connections.clone() else { return };
136134

137135
let profile = system76_profile_to_upp_str(&this.power_profile);
138136
(upp, hadess, profile)
@@ -300,8 +298,8 @@ impl System76Power {
300298
}
301299

302300
async fn set_charge_thresholds(&mut self, thresholds: (u8, u8)) -> zbus::fdo::Result<()> {
303-
let connection = &self.0.lock().await.connection;
304-
let polkit = zbus_polkit::policykit1::AuthorityProxy::new(connection)
301+
let connection = zbus::Connection::system().await?;
302+
let polkit = zbus_polkit::policykit1::AuthorityProxy::new(&connection)
305303
.await
306304
.context("could not connect to polkit authority daemon")
307305
.map_err(zbus_error_from_display)?;
@@ -410,9 +408,11 @@ impl UPowerPowerProfiles {
410408
self.apply_held_profile().await;
411409

412410
let this = self.0.lock().await;
413-
if let Ok(context) =
414-
zbus::SignalContext::new(&this.connection, POWER_PROFILES_DBUS_PATH)
415-
{
411+
let Some((_, ref connection, _)) = this.connections else {
412+
return;
413+
};
414+
415+
if let Ok(context) = zbus::SignalContext::new(connection, POWER_PROFILES_DBUS_PATH) {
416416
let _res = Self::profile_released(&context, cookie);
417417
}
418418
}
@@ -436,7 +436,11 @@ impl UPowerPowerProfiles {
436436
};
437437

438438
let mut this = self.0.lock().await;
439-
if let Ok(context) = zbus::SignalContext::new(&this.connection, DBUS_PATH) {
439+
let Some((ref connection, ..)) = this.connections else {
440+
return;
441+
};
442+
443+
if let Ok(context) = zbus::SignalContext::new(connection, DBUS_PATH) {
440444
let _res =
441445
this.apply_profile(&context, func, profile).await.map_err(zbus_error_from_display);
442446
}
@@ -512,10 +516,7 @@ pub async fn daemon() -> anyhow::Result<()> {
512516

513517
PCI_RUNTIME_PM.store(pci_runtime_pm, Ordering::SeqCst);
514518

515-
let connection =
516-
zbus::Connection::system().await.context("failed to create zbus connection")?;
517-
518-
let daemon = PowerDaemon::new(connection)?;
519+
let daemon = PowerDaemon::new()?;
519520

520521
let nvidia_exists = !daemon.graphics.nvidia.is_empty();
521522

@@ -583,7 +584,8 @@ pub async fn daemon() -> anyhow::Result<()> {
583584
.await
584585
.context("unable to create system service for com.system76.PowerDaemon")?;
585586

586-
system76_daemon.0.lock().await.connections = Some((upp_connection, hadess_connection));
587+
system76_daemon.0.lock().await.connections =
588+
Some((connection.clone(), upp_connection, hadess_connection));
587589

588590
let context = zbus::SignalContext::new(&connection, DBUS_PATH)
589591
.context("unable to create signal context")?;

0 commit comments

Comments
 (0)