From e1242546f254f80e2767def0608a0d1f39971c06 Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Thu, 11 Jun 2026 21:25:28 +0000 Subject: [PATCH] fix(headless-kde): don't let set -e abort the session when Xwayland isn't up yet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Xwayland-DISPLAY poll did `d=$(pgrep -a Xwayland | grep … | head -1)`, but under `set -euo pipefail` pgrep/grep exit non-zero when Xwayland isn't running, so the command substitution failed and `set -e` aborted the WHOLE script — killing KWin with it — on the loop's first iteration instead of polling. It only ever worked when launched from an interactive shell where Xwayland happened to already be up (so pgrep matched on try 1). Under the systemd boot appliance (punktfunk-kde-session.service) Xwayland isn't up that early, so the session crash-looped (restart counter climbing, KWin never staying), the host had no compositor, and clients couldn't connect. Append `|| true` to the substitution so the loop polls as intended and a session with no Xwayland at all still proceeds (DISPLAY just stays unset → warn). Verified live: the unit now stays active (0 restarts), KWin + the wayland-kde socket persist, probe-compositor reports ready, and a real client session captured 4.8 MB of H.265 off the running serve --native host. Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/headless/run-headless-kde.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/headless/run-headless-kde.sh b/scripts/headless/run-headless-kde.sh index 392acb4..64be292 100755 --- a/scripts/headless/run-headless-kde.sh +++ b/scripts/headless/run-headless-kde.sh @@ -74,7 +74,11 @@ echo "KWin ready." # plasma menu / D-Bus activation. KWin brings Xwayland up a moment after itself; poll for it. DISPLAY_NUM="" for _ in $(seq 1 20); do - d=$(pgrep -a Xwayland 2>/dev/null | grep -oE ' :[0-9]+' | tr -d ' :' | head -1) + # `|| true`: under `set -euo pipefail`, pgrep/grep exit non-zero when Xwayland isn't up yet + # (common a few seconds into a systemd-launched boot), which would abort the WHOLE script — + # killing KWin — on the first iteration instead of retrying. Tolerate it so the loop polls, + # and so a session with no Xwayland at all still proceeds (DISPLAY just stays unset → warn). + d=$(pgrep -a Xwayland 2>/dev/null | grep -oE ' :[0-9]+' | tr -d ' :' | head -1 || true) if [[ -n "$d" && -S "/tmp/.X11-unix/X$d" ]]; then DISPLAY_NUM="$d"; break; fi sleep 0.25 done