From d41ca88f767f93dc6e2c60443aecf7fde82eb32a Mon Sep 17 00:00:00 2001 From: Afonso Oliveira Date: Mon, 7 Sep 2026 00:03:53 +0100 Subject: [PATCH] Wait for the actual Stay Awake launcher --- bin/omarchy-update-stay-awake | 6 +++++- test/shell.d/update-lock-test.sh | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/omarchy-update-stay-awake b/bin/omarchy-update-stay-awake index 4b214ca0..ff311561 100755 --- a/bin/omarchy-update-stay-awake +++ b/bin/omarchy-update-stay-awake @@ -93,6 +93,7 @@ stop() { start() { local idle_owner="$$:$RANDOM:$RANDOM" + local launcher_pid="" stop mkdir -p "$state_dir" @@ -116,16 +117,19 @@ start() { if (( EUID == 0 )); then ( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&- exec "${hold_command[@]}" ) & + launcher_pid=$! elif [[ -t 0 ]]; then /usr/bin/sudo -N -b -- "${hold_command[@]}" else ( [[ -z ${OMARCHY_UPDATE_LOCK_FD:-} ]] || exec {OMARCHY_UPDATE_LOCK_FD}>&- exec pkexec "${hold_command[@]}" ) & + launcher_pid=$! fi # For graphical authentication the launcher may wait for a password. Wait for # either the user-owned held command to become ready or the launcher to fail. - local launcher_pid=${!:-} + # sudo -b backgrounds internally, so Bash has no launcher PID in the TTY path; + # $! there can still refer to a completed startup process substitution. local readiness_attempts=0 while [[ ! -s $inhibit_pid_file ]]; do if [[ -n $launcher_pid ]] && ! kill -0 "$launcher_pid" 2>/dev/null; then diff --git a/test/shell.d/update-lock-test.sh b/test/shell.d/update-lock-test.sh index 5b0e3b54..846e968a 100644 --- a/test/shell.d/update-lock-test.sh +++ b/test/shell.d/update-lock-test.sh @@ -141,18 +141,18 @@ if (( EUID != 0 )); then pkexec_marker="$test_tmp/pkexec-used" terminal_inhibit_pid_file="$test_tmp/terminal-inhibit-pid" write_stub pkexec '[[ -z ${PKEXEC_MARKER:-} ]] || touch "$PKEXEC_MARKER"; exec "$@"' + write_stub systemd-inhibit 'sleep 0.2; while [[ $1 == --* ]]; do shift; done; exec "$@"' - # start leaves the inhibitor running on purpose, but script tears the pty down - # the moment its command returns, which SIGHUPs that inhibitor before it can - # exec. Keep the session open from the inside until the stub has logged. + # sudo -b returns before its child is ready. Require start to wait for the + # delayed child and succeed, then stop it before script tears down the PTY. terminal_driver="$test_tmp/terminal-stay-awake" cat >"$terminal_driver" <<'SH' #!/bin/bash +set -euo pipefail omarchy-update-stay-awake start -for _ in {1..200}; do - grep -q -- '^sudo -N -b -- ' "$SUDO_LOG" && break - sleep 0.05 -done +[[ -s $XDG_RUNTIME_DIR/omarchy-update-stay-awake/inhibit-pid ]] +omarchy-update-stay-awake stop +[[ ! -e $XDG_RUNTIME_DIR/omarchy-update-stay-awake/inhibit-pid ]] SH chmod +x "$terminal_driver"