Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: Update D-Bus activation environment also on non-systemd systems #1038

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 24 additions & 1 deletion src/dbus/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::state::{BackendData, State};
use crate::state::{BackendData, Common, State};
use anyhow::{Context, Result};
use calloop::{InsertError, LoopHandle, RegistrationToken};
use std::collections::HashMap;
use zbus::blocking::{fdo::DBusProxy, Connection};

mod power;

Expand Down Expand Up @@ -64,3 +66,24 @@ pub fn init(evlh: &LoopHandle<'static, State>) -> Result<Vec<RegistrationToken>>

Ok(tokens)
}

/// Updated the D-Bus activation environment with `WAYLAND_DISPLAY` and
/// `DISPLAY` variables.
pub fn ready(common: &Common) -> Result<()> {
let conn = Connection::session()?;
let proxy = DBusProxy::new(&conn)?;

proxy.update_activation_environment(HashMap::from([
("WAYLAND_DISPLAY", common.socket.to_str().unwrap()),
(
"DISPLAY",
&common
.xwayland_state
.as_ref()
.map(|s| format!(":{}", s.display))
.unwrap_or(String::new()),
),
]))?;

Ok(())
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ impl State {
// into systemd and the session?
self.ready.call_once(|| {
// potentially tell systemd we are setup now
#[cfg(feature = "systemd")]
if let state::BackendData::Kms(_) = &self.backend {
#[cfg(feature = "systemd")]
systemd::ready(&self.common);
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 was thinking about replacing the systemd::ready entirely with dbus::ready, I think that should work as well. What's good about the dbus solution is not calling external binaries. For now I didn't remove systemd::ready in case you consider that too intrusive. I would love to hear your thoughts here.

What I can confirm is that this patch fixes flatpak Steam on my Gentoo+openrc installation.

Copy link
Member

Choose a reason for hiding this comment

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

The systemd environment is still something separate from the dbus environment, the dbus-broker just happens to import it on systems with systemd.

Just updating the dbus activation environment would this break e.g. systemd user services. I think this is a sensible solution. If calling external binaries would really be a problem, we could also trigger the systemd interface via dbus, but given this is a one time startup thing, I wouldn't bother.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, thanks!

#[cfg(not(feature = "systemd"))]
if let Err(err) = dbus::ready(&self.common) {
error!(?err, "Failed to update the D-Bus activation environment");
}
}

// potentially tell the session we are setup now
Expand Down
Loading