Wait for the actual Stay Awake launcher
This commit is contained in:
1 parent
978dffaa3e
commit
d41ca88f76
2 files changed
+12
-8
No files matched your search
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in new issue
Block a user