Session: wait for the document portal's mount before reopening apps; say when it's broken
CI / test (push) Canceled after 1m11s

V's session.log had kwi (a Flatpak) failing with "bwrap: Can't find source path
/run/user/1000/doc/by-app/org.kde.kwi". At login chandra-session restarts
xdg-desktop-portal, and xdg-document-portal stopped and started with it in the
same second (V's journal, 21:36:12); a Flatpak started in that gap, such as one
session restore reopens, finds no FUSE mount to bind into its sandbox.

When flatpak is installed, chandra-session now asks the document portal for its
mount point (which also starts it), waits up to 5 s for the FUSE mount and
checks it answers. If it doesn't, the reason goes to the log and into
CHANDRA_SESSION_ERRORS, which the shell shows as an error notice once the desktop
is up (DesktopShell::show_session_errors). A missing dbus-send is reported too.

Tested: the snippet against a real xdg-document-portal on a dbus-run-session bus
(mounted after 0 waits) and with an unreachable bus (error text); the notice in
compositor/host/launch_test.mbt and headless with build/wasmhost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiGJWeuHiTgtoyB4kb
This commit is contained in:
Claude committed 2026-11-26 06:29:54 +00:00
1 parent 70b24ffe47
commit 2752b81e36
3 files changed
+62

No files matched your search

+33
View File
@@ -149,6 +149,39 @@ if command -v systemctl >/dev/null 2>&1; then
systemctl --user try-restart xdg-desktop-portal.service >>"$log" 2>&1 || true
fi
# Flatpak apps need the document portal's FUSE mount: `flatpak run` binds
# $XDG_RUNTIME_DIR/doc/by-app/APP into the sandbox, and bwrap dies ("Can't find source path
# .../doc/by-app/org.kde.kwi") while nothing is mounted there. The portal restart above stops and
# starts xdg-document-portal too, so wait (up to 5 s) for its mount before the compositor reopens
# the last session's apps. A portal that doesn't come up is shown on screen when the desktop
# starts (CHANDRA_SESSION_ERRORS) and logged, not left for each Flatpak launch to hit.
session_errors=
doc_mounted() { # PATH -> success when a FUSE file system is mounted at PATH
awk -v m="$1" '$5 == m && / - fuse/ { f = 1 } END { exit !f }' /proc/self/mountinfo
}
if command -v flatpak >/dev/null 2>&1; then
doc="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/doc"
if ! command -v dbus-send >/dev/null 2>&1; then
session_errors="Flatpak apps can't be checked: dbus-send is not installed (package dbus-bin or dbus)"
elif ! out=$(dbus-send --session --print-reply=literal --dest=org.freedesktop.portal.Documents \
/org/freedesktop/portal/documents org.freedesktop.portal.Documents.GetMountPoint 2>&1); then
# Asking also starts xdg-document-portal when it isn't running.
session_errors="Flatpak apps can't start: the document portal (xdg-document-portal) did not answer: $out"
else
i=0
while [ $i -lt 50 ] && ! doc_mounted "$doc"; do sleep 0.1; i=$((i + 1)); done
if ! doc_mounted "$doc"; then
session_errors="Flatpak apps can't start: the document portal answered but nothing is mounted at $doc (see: journalctl --user -b -u xdg-document-portal)"
elif ! ls "$doc/by-app" >/dev/null 2>&1; then
session_errors="Flatpak apps can't start: the document portal's mount at $doc does not answer ($(ls "$doc/by-app" 2>&1 | head -1))"
else
echo "chandra-session: document portal mounted at $doc after $i waits" >>"$log"
fi
fi
[ -n "$session_errors" ] && echo "chandra-session: $session_errors" >>"$log"
fi
export CHANDRA_SESSION_ERRORS="$session_errors"
# Hand the PAM-started gnome-keyring daemon (already unlocked by the login password) its session
# components, so it owns org.freedesktop.secrets on our bus. (oo7-daemon needs none of this: it
# is started by systemd and unlocked over its PAM socket; see docs/keyring.md.) Harmless if it isn't installed,