Login session: keep the real session bus so the PAM-unlocked GNOME keyring works
As a login session, launched apps were put on a private dbus-daemon bus (meant only to stop single-instance apps forwarding to a host session when nested). That bus has no org.freedesktop.secrets, so apps D-Bus-activated a second, locked gnome-keyring-daemon on it: unlock prompts / "create default keyring" dialogs, even though pam_gnome_keyring had already unlocked the login keyring. The session script also wrapped everything in dbus-run-session whenever DBUS_SESSION_BUS_ADDRESS was unset, splitting off from systemd's user bus. - host-wasm + native sys stub: start the private bus only when nested (WAYLAND_DISPLAY or DISPLAY set); under --drm apps use the session bus. - moon-plasma-session: use $XDG_RUNTIME_DIR/bus when it exists, fall back to re-running itself under dbus-run-session; push WAYLAND_DISPLAY and XDG_* into the D-Bus/systemd activation environment so gcr-prompter can show unlock prompts; run gnome-keyring-daemon --start --components=secrets. - justfile run-drm(-native): update the activation environment too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hhWvZgm7r2v8NpS2g4
This commit is contained in:
4 files changed
+63
-5
No files matched your search
@@ -337,13 +337,24 @@ int32_t mp_has_exe(moonbit_bytes_t name_bytes) {
|
|||||||
|
|
||||||
/* Private session bus for launched apps, so single-instance apps (Firefox, Kate,
|
/* Private session bus for launched apps, so single-instance apps (Firefox, Kate,
|
||||||
* Dolphin...) don't forward the launch to an instance on the host session.
|
* Dolphin...) don't forward the launch to an instance on the host session.
|
||||||
* Started lazily; dies with the compositor. */
|
* Started lazily; dies with the compositor.
|
||||||
|
*
|
||||||
|
* Only when nested inside another graphical session (WAYLAND_DISPLAY or DISPLAY set).
|
||||||
|
* As a login session (--drm) the session bus is ours, and it is where the PAM-unlocked
|
||||||
|
* gnome-keyring (org.freedesktop.secrets), portals and notifications live: a private bus
|
||||||
|
* would hide them, so apps would D-Bus-activate a fresh, locked keyring on it. */
|
||||||
static char private_bus[256];
|
static char private_bus[256];
|
||||||
static int private_bus_tried = 0;
|
static int private_bus_tried = 0;
|
||||||
|
|
||||||
|
static int env_set(const char *name) {
|
||||||
|
const char *v = getenv(name);
|
||||||
|
return v && v[0];
|
||||||
|
}
|
||||||
|
|
||||||
static void start_private_bus(void) {
|
static void start_private_bus(void) {
|
||||||
if (private_bus_tried) return;
|
if (private_bus_tried) return;
|
||||||
private_bus_tried = 1;
|
private_bus_tried = 1;
|
||||||
|
if (!env_set("WAYLAND_DISPLAY") && !env_set("DISPLAY")) return;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
if (pipe(fds) != 0) return;
|
if (pipe(fds) != 0) return;
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|||||||
@@ -77,11 +77,22 @@ fn set_nonblock_cloexec(fd: i32) {
|
|||||||
impl State {
|
impl State {
|
||||||
/// A private session bus, so single-instance apps (Firefox, Kate, Dolphin...) don't forward
|
/// A private session bus, so single-instance apps (Firefox, Kate, Dolphin...) don't forward
|
||||||
/// their launch to an instance on the host session. Dies with this process.
|
/// their launch to an instance on the host session. Dies with this process.
|
||||||
|
///
|
||||||
|
/// Only when nested inside another graphical session (WAYLAND_DISPLAY or DISPLAY set). As a
|
||||||
|
/// login session (--drm from a VT or the display manager) the session bus *is* ours, and it is
|
||||||
|
/// where the PAM-unlocked gnome-keyring (org.freedesktop.secrets), portals and notifications
|
||||||
|
/// live: a private bus would hide them, so apps D-Bus-activate a fresh, locked keyring on it.
|
||||||
fn private_bus(&mut self) -> Option<String> {
|
fn private_bus(&mut self) -> Option<String> {
|
||||||
if self.bus_tried {
|
if self.bus_tried {
|
||||||
return self.private_bus.clone();
|
return self.private_bus.clone();
|
||||||
}
|
}
|
||||||
self.bus_tried = true;
|
self.bus_tried = true;
|
||||||
|
let nested = ["WAYLAND_DISPLAY", "DISPLAY"]
|
||||||
|
.iter()
|
||||||
|
.any(|v| std::env::var_os(v).map(|x| !x.is_empty()).unwrap_or(false));
|
||||||
|
if !nested {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let mut cmd = Command::new("dbus-daemon");
|
let mut cmd = Command::new("dbus-daemon");
|
||||||
cmd.args(["--session", "--nofork", "--print-address=1"])
|
cmd.args(["--session", "--nofork", "--print-address=1"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
|
|||||||
@@ -73,11 +73,14 @@ run-headless: build modules
|
|||||||
# Run the wasm compositor on the real display (DRM/KMS + libinput, through the host). Run from a login VT (Ctrl+Alt+F3), not inside another session. Ctrl+Alt+Backspace quits, Ctrl+Alt+F<n> switches VT.
|
# Run the wasm compositor on the real display (DRM/KMS + libinput, through the host). Run from a login VT (Ctrl+Alt+F3), not inside another session. Ctrl+Alt+Backspace quits, Ctrl+Alt+F<n> switches VT.
|
||||||
run-drm: compositor-wasm host-wasm modules
|
run-drm: compositor-wasm host-wasm modules
|
||||||
rm -f {{socket}}
|
rm -f {{socket}}
|
||||||
|
# Let D-Bus-activated helpers (gcr-prompter's keyring unlock prompt, portals) open windows here.
|
||||||
|
-dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=moon-plasma 2>/dev/null
|
||||||
host-wasm/target/release/moon-plasma-host build/compositor.wasm --drm --socket {{socket}} --theme {{theme}}
|
host-wasm/target/release/moon-plasma-host build/compositor.wasm --drm --socket {{socket}} --theme {{theme}}
|
||||||
|
|
||||||
# The same on the native compositor (system-cc release build), for comparison.
|
# The same on the native compositor (system-cc release build), for comparison.
|
||||||
run-drm-native: build-release modules
|
run-drm-native: build-release modules
|
||||||
rm -f {{socket}}
|
rm -f {{socket}}
|
||||||
|
-dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=moon-plasma 2>/dev/null
|
||||||
{{release_exe}} --drm --socket {{socket}} --theme {{theme}}
|
{{release_exe}} --drm --socket {{socket}} --theme {{theme}}
|
||||||
|
|
||||||
# Install the Moon Plasma login session (display-manager entry): the wasm compositor + its host. Asks for root once.
|
# Install the Moon Plasma login session (display-manager entry): the wasm compositor + its host. Asks for root once.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
# WebAssembly component, run by moon-plasma-host; if only the native binary was installed
|
# WebAssembly component, run by moon-plasma-host; if only the native binary was installed
|
||||||
# (session/install.py --native), it runs that instead.
|
# (session/install.py --native), it runs that instead.
|
||||||
share=/usr/local/share/moon-plasma
|
share=/usr/local/share/moon-plasma
|
||||||
|
case "$0" in /*) self="$0" ;; *) self="$PWD/$0" ;; esac # for the dbus-run-session re-exec
|
||||||
|
|
||||||
export XDG_SESSION_TYPE=wayland
|
export XDG_SESSION_TYPE=wayland
|
||||||
export XDG_CURRENT_DESKTOP=moon-plasma
|
export XDG_CURRENT_DESKTOP=moon-plasma
|
||||||
@@ -15,6 +16,8 @@ export SDL_VIDEODRIVER=wayland
|
|||||||
|
|
||||||
mkdir -p "$HOME/.local/state/moon-plasma"
|
mkdir -p "$HOME/.local/state/moon-plasma"
|
||||||
log="$HOME/.local/state/moon-plasma/session.log"
|
log="$HOME/.local/state/moon-plasma/session.log"
|
||||||
|
[ -n "$MOON_PLASMA_SESSION_LOG_STARTED" ] || : >"$log"
|
||||||
|
export MOON_PLASMA_SESSION_LOG_STARTED=1
|
||||||
|
|
||||||
# The compositor reads wit/ and config/ relative to its working directory.
|
# The compositor reads wit/ and config/ relative to its working directory.
|
||||||
cd "$share" || exit 1
|
cd "$share" || exit 1
|
||||||
@@ -28,9 +31,39 @@ else
|
|||||||
set -- /usr/local/bin/moon-plasma
|
set -- /usr/local/bin/moon-plasma
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && command -v dbus-run-session >/dev/null 2>&1; then
|
# Session bus. Use the per-user bus (systemd's $XDG_RUNTIME_DIR/bus) when there is one: that is
|
||||||
exec dbus-run-session -- "$@" --drm --socket "$sock" \
|
# where pam_gnome_keyring's daemon, unlocked with the login password, registers
|
||||||
--theme "$share/config/themes/moon-night.json" >"$log" 2>&1
|
# org.freedesktop.secrets. A fresh dbus-run-session bus would hide it, and apps would then
|
||||||
|
# activate a second, locked keyring daemon there (unlock prompts, "default keyring" dialogs).
|
||||||
|
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && [ -S "${XDG_RUNTIME_DIR:-/nonexistent}/bus" ]; then
|
||||||
|
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
|
||||||
fi
|
fi
|
||||||
|
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] && command -v dbus-run-session >/dev/null 2>&1; then
|
||||||
|
# No bus yet (no systemd user session): start one and run this script again inside it, so the
|
||||||
|
# environment setup below happens on that bus.
|
||||||
|
exec dbus-run-session -- "$self"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# D-Bus- and systemd-activated services (gcr-prompter for keyring unlock prompts, portals,
|
||||||
|
# notification daemons) start with the activation environment, not ours: without
|
||||||
|
# WAYLAND_DISPLAY they can't open a window, so a keyring unlock prompt silently fails and the
|
||||||
|
# app gets "locked collection" errors.
|
||||||
|
if command -v dbus-update-activation-environment >/dev/null 2>&1; then
|
||||||
|
dbus-update-activation-environment --systemd \
|
||||||
|
WAYLAND_DISPLAY="$(basename "$sock")" XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \
|
||||||
|
XDG_SESSION_DESKTOP >>"$log" 2>&1 ||
|
||||||
|
dbus-update-activation-environment \
|
||||||
|
WAYLAND_DISPLAY="$(basename "$sock")" XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \
|
||||||
|
XDG_SESSION_DESKTOP >>"$log" 2>&1 || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Hand the PAM-started keyring daemon (already unlocked by the login password) its session
|
||||||
|
# components, so it owns org.freedesktop.secrets on our bus. Harmless if it isn't installed,
|
||||||
|
# already running under systemd's socket units, or not unlocked by PAM (it then prompts once).
|
||||||
|
if command -v gnome-keyring-daemon >/dev/null 2>&1; then
|
||||||
|
eval "$(gnome-keyring-daemon --start --components=secrets 2>>"$log")"
|
||||||
|
[ -n "$SSH_AUTH_SOCK" ] && export SSH_AUTH_SOCK
|
||||||
|
fi
|
||||||
|
|
||||||
exec "$@" --drm --socket "$sock" \
|
exec "$@" --drm --socket "$sock" \
|
||||||
--theme "$share/config/themes/moon-night.json" >"$log" 2>&1
|
--theme "$share/config/themes/moon-night.json" >>"$log" 2>&1
|
||||||
Reference in new issue
Block a user