Sfoglia il codice sorgente

fix(spoolbuddy): add idle-watchdog diagnostics and Wayland autodetect (#937)

  Follow-up to the SpoolBuddy LCD power-off fix. Field-testing on a
  Raspberry Pi OS Bookworm kiosk showed the watchdog appearing absent
  from `ps ax | grep spool` — actually it had already `exec`'d into
  `swayidle`, but with no logging there was no way to confirm that
  without manually re-running the script.

  - spoolbuddy-idle.sh now redirects stdout+stderr to
    ~/.cache/spoolbuddy-idle.log and prints WAYLAND_DISPLAY,
    XDG_RUNTIME_DIR, PATH, the resolved timeout, and the final
    `swayidle` command line on every start.
  - Auto-detect WAYLAND_DISPLAY by scanning $XDG_RUNTIME_DIR for a
    wayland-* socket (10s retry loop) so the script survives the race
    where labwc launches autostart before exporting its env.
  - Default XDG_RUNTIME_DIR to /run/user/$(id -u) if unset.
maziggy 1 mese fa
parent
commit
d42250cb68
2 ha cambiato i file con 31 aggiunte e 1 eliminazioni
  1. 0 1
      CHANGELOG.md
  2. 31 0
      spoolbuddy/install/spoolbuddy-idle.sh

File diff suppressed because it is too large
+ 0 - 1
CHANGELOG.md


+ 31 - 0
spoolbuddy/install/spoolbuddy-idle.sh

@@ -12,10 +12,39 @@
 
 set -u
 
+LOG_FILE="${SPOOLBUDDY_IDLE_LOG:-$HOME/.cache/spoolbuddy-idle.log}"
+mkdir -p "$(dirname "$LOG_FILE")" 2>/dev/null || true
+exec >>"$LOG_FILE" 2>&1
+echo "=== $(date -Is) spoolbuddy-idle starting (pid=$$) ==="
+echo "WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-<unset>}"
+echo "XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-<unset>}"
+echo "PATH=$PATH"
+
 DEFAULT_TIMEOUT=300
 ENV_FILE="${SPOOLBUDDY_ENV_FILE:-/opt/bambuddy/spoolbuddy/.env}"
 OUTPUT="${SPOOLBUDDY_DISPLAY_OUTPUT:-HDMI-A-1}"
 
+# Wait for labwc to actually bring up its Wayland socket. Autostart fires
+# before labwc finishes exporting WAYLAND_DISPLAY on some systems, which
+# makes swayidle exit immediately.
+if [ -z "${WAYLAND_DISPLAY:-}" ] && [ -n "${XDG_RUNTIME_DIR:-}" ]; then
+    for _ in $(seq 1 20); do
+        sock=$(ls -1 "$XDG_RUNTIME_DIR"/wayland-* 2>/dev/null | grep -v '\.lock$' | head -n1 || true)
+        if [ -n "$sock" ]; then
+            WAYLAND_DISPLAY="$(basename "$sock")"
+            export WAYLAND_DISPLAY
+            echo "auto-detected WAYLAND_DISPLAY=$WAYLAND_DISPLAY"
+            break
+        fi
+        sleep 0.5
+    done
+fi
+if [ -z "${XDG_RUNTIME_DIR:-}" ]; then
+    XDG_RUNTIME_DIR="/run/user/$(id -u)"
+    export XDG_RUNTIME_DIR
+    echo "defaulted XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR"
+fi
+
 if [ -r "$ENV_FILE" ]; then
     set -a
     # shellcheck disable=SC1090
@@ -58,9 +87,11 @@ fi
 
 if [ "$TIMEOUT" -le 0 ]; then
     # Blanking explicitly disabled — don't launch swayidle at all.
+    echo "timeout<=0, sleeping forever"
     exec sleep infinity
 fi
 
+echo "execing swayidle with timeout=$TIMEOUT output=$OUTPUT"
 exec swayidle -w \
     timeout "$TIMEOUT" "wlopm --off $OUTPUT" \
     resume "wlopm --on $OUTPUT"

Some files were not shown because too many files changed in this diff